Docker – to be continued

Building from Dockerfile

docker build [directory with Dockerfile]

Example Dockerfile:

FROM fedora:25

RUN dnf install -y java-1.8.0-openjdk git maven mc vim unzip \
&& cd /tmp && git clone swarm

WORKDIR /tmp/swarm

ENTRYPOINT mvn clean install

FROM specifies a parent image

RUN specifies a command that is run during the image build. The results of the command are stored in the image.
One can put multiple RUNs in a Dockerfile, but each will result in a new layer/image. It makes sense if you have a part of RUN that you are unlikely to modify. This will result in reusing of the layer from the first build in the consecutive builds, thus speeding up your work.

ENTRYPOINT is executed after container start. It is executed regardless of any command provided by docker run.
If you don’t want to run the start-up code in the case a user provides some run command, use CMD instead.
One can mix ENTRYPOINT with CMD, more details about the two:


docker run [image name]

To get into container’s bash:

docker run -it [image name] bash

To resurrect a container:
commit a stopped container:

docker commit [container sha] tmp

Start the container (in the example below, overriding entrypoint, because it was already ran):

docker run -ti --entrypoint=/bin/bash tmp

Sharing files between host and container

Mounting a host directory into a container:

docker run -v [host directory]:[container directory] [image name]

Copying files from docker to host (may be working both ways in new versions):

docker cp [container]:[container file/directory] [host target]