Why are valid directives in my Dockerfile apparently being ignored? Using the following Dockerfile:

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"]


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 "&lt;string&gt;", line 1, in &lt;module&gt;
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' &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:


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
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 \
    &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
...


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