{id: commands}
{id: dockerfile-commands}
{aside} There is only a handfull of commands that you can use in a Dockerfile. We are going to cover them one-by-one briefly. {/aside}
{id: docker-from} {i: FROM}
- Declare the base-image.
- This is how we start all the Dockerfiles. (thought we could put some ARGs before)
- FROM
{id: docker-copy} {i: COPY}
- COPY
- COPY from host to image
{id: docker-arg} {i: ARG}
{id: docker-add} {i: ADD}
- ADD
- ADD is like COPY but it can do more magic (can download files from the internet, automatically unpacks zipped files)
{id: docker-run} {i: RUN}
Execute some command during the creation of the Docker image.
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y some-package
{id: docker-cmd} {i: CMD}
CMD - the default command when the container starts
In Debian it is bash.
The CMD only runs when we run the container!
{id: docker-entrypoint} {i: ENTRYPOINT}
{id: docker-env} {i: ENV}
{id: docker-workdir} {i: WORKDIR}
{id: docker-upload}
docker tag ID szabgab/name:1.01
docker login --username=szabgab
docker push szabgab/name:1.01
{id: docker-ps} {i: exec}
docker run --rm -d -it debian
docker ps
docker stop ID
docker exec 0ca23b8a9802 echo hello
docker exec -it 0ca23b8a9802 bash
docker kill ID if it does not want to stop
{id: docker-dockerfile}
Dockerfile
FROM debian
RUN apt-get update
RUN apt-get install -y htop
RUN apt-get install -y curl
docker build -t exp1 .
docker images
docker history exp1
docker run --rm -it exp1
{id: simple-docker-commands}
Empty state, no images:
no runnin containers
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
no local containers at all (including not running, and showing the size)
$ docker ps -as
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
not even images
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Commands
docker ps
docker ps -as list all the containers available locally (incl the size)
docker images list images
{id: passing-commands-to-docker-container}
$ docker run mydocker ls -l /
$ docker run mydocker perl -v
This is perl 5, version 22, subversion 2 (v5.22.2) built for x86_64-linux-gnu-thread-multi
....
$ docker run mydocker python -V
container_linux.go:247: starting container process caused "exec: \"python\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"python\": executable file not found in $PATH".
ERRO[0001] error getting events from daemon: net/http: request canceled
{id: run-container-as-a-daemon-attach-detach} {i: attach} {i: -d} {i: exec}
- Run as a Daemon in the background name it 'test'
docker run -d --rm -it --name test busybox
- Check if it is running using
docker ps
Run things on it
docker exec CONTAINER command (eg ls, cat ...)
- Attach to it:
docker container attach test
- Detach from the container and keep it running by pressing
Ctrl-p Ctrl-q
{id: run-container-as-a-daemon} {i: inspect} {i: logs}
{aside} In this example we create a Docker image based on busybox and tiny bit of shell command. Specifically we'll run an infinite while-loop and every second we'll print the current date and time.
The first thing we need to do is to build the {/aside}
docker build -t mydocker .
docker run -d --rm --name test mydocker
docker inspect test
docker container logs test
docker container attach test
Ctrl-p Ctrl-q
{id: inspect-docker-container} {i: inspect}
docker inspect CONTAINER_ID
{id: copy-console-of-container} {i: logs}
docker logs CONTAINER_ID
{id: ignore-files-and-directories} {i: .dockerignore}
docker build .
will send over all the content of the corrent directory to the docker
daemon. You usually don't want that. So add a file called .dockerignore
to the root
of your project
.git/
temp/