The first mistake is to think that a Docker image/container is similar to a virtual machine. There are resemblances but they aren't the same and frankly, not really similar.
Docker is not, really, for running an OS. It is for running a single process in a contained (isolated) environment. The container uses the same kernel as what is on the host.
When you create a Docker image with FROM ubuntu
you are starting your image with some pre-created layers that brings in some parts of a standard file system and packages you would find on a Ubuntu server.
Then you add your own additional layers, adding binaries and files that are necessary to run your program / process.
The image would (normally but not mandatory) have a CMD
command or ENTRYPOINT
command to run something.
Each line in a Dockerfile
is a command instructing Docker on how to create the image. Each line/command result in one more layer. To install packages, you probably want to do something like this:
FROM ubuntu:16.04
RUN apt-get -qq update && \
apt-get -y install build-essential autoconf libtool && \
apt-get install -y python-setuptools python-dev python3-dev && \
apt-get install -y python-pip python3-pip && \
apt-get install -y python-virtualenv unixodbc-dev libffi-dev git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
That will keep your image smaller.
Then you will need to actually run something...
CMD python
Then you can build your image:
docker build -t myimage .
And use it...
docker run --rm -it myimage
ifconfig
does not work because the binary is not in the image. It is not really necessary as you don't manage the network from within the container.
So you seem to be making a container to build some code. You would want to mount your directory with the code inside the container when you run it. I don't know what OS you run on your workstation or server so I will refer to this post for more information: https://stackoverflow.com/questions/41485217/mount-current-directory-as-a-volume-in-docker-on-windows-10/41489151#41489151
Let's say you are building with the command make
, you could do this:
docker run --rm -it -v $(pwd):/usr/src/project myimage make
This would require a line in your Dockerfile
to make the working dir /usr/src/project
:
WORKDIR /usr/src/project
What will happen if you ran the docker
command line above is that it will create a container from the image named myimage
(build command shown earlier), mount the current directory you are in as /usr/src/project
inside the new container. Run the make
command inside the container and then exit. The --rm
parameter tells Docker to not keep the container around once it finish running. The -it
parameters mean interactive
and tty
.
If you wanted to just have access to some shell so you could manually run make
or other commands in a ad-hoc fashion, you could also do this:
docker run --rm -it -v $(pwd):/usr/src/project myimage /bin/bash
This would create the container from the myimage
image, and run bash
. Because bash
does not exit and you have the -it
parameter, you will be at the container's prompt where you can do whatever you want.
Just remember that any file you modify from inside the container will not be preserved and next time you start back to default state. Of course any files from the /usr/src/project
directory will be modified on your local hard drive as this is mounted from it.