0

Using the following Dockerfile:

FROM ubuntu:latest

USER root

RUN apt-get -y update \
    && apt-get -y upgrade \
    && apt-get install -y \
        python-pip \
        nmap \
        vim-tiny

FROM python:2.7

USER root

RUN pip install --no-cache-dir cassandra-driver

FROM cassandra:3.11.4

WORKDIR /cassandra

COPY ./cassandra.yaml /etc/cassandra/cassandra.yaml

EXPOSE 7000 7001 7199 9042 9171

CMD ["cassandra", "-f"]

and then running the commands:

docker system prune -a -f

docker-compose -f docker-compose.yml -f dev-docker-compose.yml up --build

when I then enter the cassandra container via the command:

docker exec -ti cassandra_app /bin/bash

None of the things I asked for has been installed!

root@2f1776a10084:/cassandra# nmap
bash: nmap: command not found

root@2f1776a10084:/cassandra# vi
bash: vi: command not found

root@2f1776a10084:/cassandra# python --version
Python 2.7.13

root@2f1776a10084:/cassandra# python -c "import cassandra"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named cassandra

I also tried running the build with the "USER root" lines removed, but no difference.

I need a Cassandra container that includes "vi" and the python cassandra driver, and this wretched Docker is wasting hours and hours of my time trundling through its builds (which don't have any relevant error messages that I can see).

It has gradually become clear that Docker caches things when it can, hence the "-a -f" arguments to the "docker prune" command - I want to be sure I'm doing a clean build each time.

In case it is relevant, following are the Docker YAML files for the above build command:

docker_compose.yml :

version: '3.3'

services:

  application:
#    image: appweb/app:python3
    container_name: django_app
    build:
      context: ./application
    ports:
      - "8000"
     depends_on:
      - postgres
      - cassandra
      - cassandra-node
    networks:
      - appnet
    environment:
      - DOCKERISED=1
      - CASS_HOST1=cassandra:9042
      - CASS_HOST2=cassandra-node:9042
    extra_hosts:
      - "34.253.98.48:34.253.98.47"

  postgres:
    image: postgres:9.6.10
    container_name: postgres_app
    networks:
      - appnet

  cassandra:
    build:
      dockerfile: Dockerfile
      context: ./cassandra
    container_name: cassandra_app
    environment:
      - "CASSANDRA_SEEDS=cassandra"
      - "CASSANDRA_CLUSTER_NAME=App2 Cluster"
    networks:
      - appnet

  cassandra-node:
    build:
      dockerfile: Dockerfile
      context: ./cassandra
    container_name: cassandra_app2
    #command: /bin/bash -c "echo 'Waiting for seed node' && sleep 30 && /docker-entrypoint.sh cassandra -f"
    environment:
      - "CASSANDRA_SEEDS=cassandra"
      - "CASSANDRA_CLUSTER_NAME=APp2 Cluster"
    depends_on:
      - "cassandra"
    networks:
      - appnet

networks:   appnet:

dev-docker-compose.yml :

version: '3.3'

services:

  application:
    environment:
      - CASS_USER
      - CASS_PASS
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - TESTMODE=1
      - CQLENG_ALLOW_SCHEMA_MANAGEMENT="1"
    volumes:
      - ./application/source:/application/source
      - ./application/source/private_settings.py:/application/source/app2-config/app2/config/private_settings.py

  postgres:
    volumes:
      - postgres_data:/var/lib/postgresql

  cassandra:
    volumes:
       - cassandra_data:/var/lib/cassandra

  cassandra-node:
    volumes:
       - cassandra_data2:/var/lib/cassandra

volumes:   postgres_data:   cassandra_data:   cassandra_data2:

Any ideas? Thanks in anticipation

1

It looks like your Dockerfile is attempting a multistage build:

FROM ubuntu:latest
...
FROM python:2.7
...

This is a feature that enables you to build parts of your image in a separate build container and then import what you need. Unless you import stuff into your end container, it will be lost in the build process; this is exactly what is happening with your RUN apt-get... statement. To fix it, try removing the extra stages of the build, (FROM ubuntu:latest and FROM python:2.7) and moving your commands to after FROM cassandra:3.11.4 like so:

FROM cassandra:3.11.4

USER root

RUN apt-get -y update \
    && apt-get -y upgrade \
    && apt-get install -y \
        python-pip \
        nmap \
        vim-tiny

RUN pip install --no-cache-dir cassandra-driver
...

I'm sorry you're having a hard time with Docker. Hopefully this helps and it starts making more sense. Good luck, friend!

3
  • Ah right, many thanks Steve. From seeing examples on the Web, I assumed the FROM was equivalent to no more than a python "import" and everything should end up in the same container. Out of interest, how would one include a separate container in (for this example) the cassandra container? Feb 7 '20 at 10:12
  • Ah, reading that ref you gave on multi-stage builds, I see the answer to my question is the "copy" command, although that would work easily only for containers containing everything in a well-defined set of directories, i.e. it is a file-level copy rather than reiterating an install process. Feb 7 '20 at 11:31
  • Yeah, while copying stuff from one container to another can work, it's not very recommended unless, like you said, it's just 1 or 2 files or a very well defined set of files. In this case, it's probably best to install things like python as if you were installing on it on a normal machine.
    – SteveGoob
    Feb 7 '20 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.