<p>It looks like your Dockerfile is attempting a <a href="https://docs.docker.com/develop/develop-images/multistage-build/" rel="nofollow noreferrer">multistage build</a>:</p>

<pre><code>FROM ubuntu:latest
...
FROM python:2.7
...
</code></pre>

<p>This is a feature that enables you to build parts of your image in a <em>separate</em> 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 <code>RUN apt-get...</code> statement. To fix it, try removing the extra stages of the build, (<code>FROM ubuntu:latest</code> and <code>FROM python:2.7</code>) and moving your commands to after <code>FROM cassandra:3.11.4</code> like so:</p>

<pre><code>FROM cassandra:3.11.4

USER root

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

RUN pip install --no-cache-dir cassandra-driver
...
</code></pre>

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

CC BY-SA 4.0
2020-02-07T10:12:17.350Z
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?
John Ramsden
CC BY-SA 4.0
2020-02-07T11:31:29.173Z
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.
John Ramsden
CC BY-SA 4.0
2020-02-07T17:55:19.523Z
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
CC BY-SA 4.0
2020-02-05T22:04:12.910Z
2020-02-05T22:28:34.410Z
2020-02-05T22:28:34.410Z
SteveGoob
<p>Using the following Dockerfile:</p>

<pre><code>FROM ubuntu:latest

USER root

RUN apt-get -y update \
    &amp;&amp; apt-get -y upgrade \
    &amp;&amp; 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"]
</code></pre>

<p>and then running the commands:</p>

<pre><code>docker system prune -a -f

docker-compose -f docker-compose.yml -f dev-docker-compose.yml up --build
</code></pre>

<p>when I then enter the cassandra container via the command:</p>

<pre><code>docker exec -ti cassandra_app /bin/bash
</code></pre>

<p>None of the things I asked for has been installed!</p>

<pre><code>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 "&lt;string&gt;", line 1, in &lt;module&gt;
ImportError: No module named cassandra
</code></pre>

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

<p>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).</p>

<p>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.</p>

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

<p>docker_compose.yml :</p>

<pre><code>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' &amp;&amp; sleep 30 &amp;&amp; /docker-entrypoint.sh cassandra -f"
    environment:
      - "CASSANDRA_SEEDS=cassandra"
      - "CASSANDRA_CLUSTER_NAME=APp2 Cluster"
    depends_on:
      - "cassandra"
    networks:
      - appnet

networks:   appnet:
</code></pre>

<p>dev-docker-compose.yml :</p>

<pre><code>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:
</code></pre>

<p>Any ideas? Thanks in anticipation</p>

<cassandra>
Why are valid directives in my Dockerfile apparently being ignored?
John Ramsden
# Why are valid directives in my Dockerfile apparently being ignored?

(Asked by: username_0 on 2020-02-05)

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 "", line 1, in 
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

**Tags:** cassandra


---

## 1 answers

### Answer by username_1 on 2020-02-05. Score: 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!

> **Comments:**
> **username_0**: 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?  
> **username_0**: 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.  
> **username_1**: 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.  

---

