From Dogtag
Jump to: navigation, search

Installing Docker

To install Docker from Docker repository:

$ dnf config-manager --add-repo
$ dnf install docker-ce docker-ce-cli

See Install Docker Engine on Fedora.

To install Docker from Fedora:

$ dnf install docker

Installing Docker Machine

To install Docker Machine:

$ curl -L`uname -s`-`uname -m` >/tmp/docker-machine &&
    chmod +x /tmp/docker-machine &&
    sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

See also:

Installing Docker SDK

To install Docker SDK for Python:

$ pip install docker

To test the installation:

$ python
>>> import docker
>>> client = docker.from_env()
>>> print("alpine", ["echo", "hello", "world"]))

See also:

Starting Docker Service

Start Docker service with the following command:

$ systemctl start docker
$ systemctl enable docker

Verify with the following command:

$ docker info
$ docker run hello-world
$ docker run -it ubuntu bash

Listing Images

$ docker images

Pulling an Image


$ docker pull


$ docker pull mysql


$ docker pull dogtagpki/pki-ci:f26


$ docker pull freeipa/freeipa-server

Running Container

To run a command in a new container:

$ docker run --name=<container> <image> /bin/echo "Hello World!"

To run an interactive shell in a new container:

$ docker run -ti <image> /bin/bash

To run a container in the background:

$ docker run --name=<container> --detach -i <image>

To run a command in an existing container:

$ docker exec <container> <command>

To run an interactive shell in an existing container:

$ docker exec -ti <container> /bin/bash

File Transfer

To copy a file to container:

$ docker cp <source> <container>:<target full path>

To copy a file from a container:

$ docker cp <container>:<source full path> <target>

Listing Containers

To list active containers:

$ docker ps

To list all containers:

$ docker ps --all

To list certain columns only:

$ docker ps --format 'table {{.Names}},{{.Image}},{{.Command}}'

Displaying Container Info

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <name or ID>

Attaching to a Container

To attach to an existing container:

$ docker attach <container>

To detach, press Ctrl-PQ.


To list networks:

$ docker network ls

To create a network:

$ docker network create <network>

To attach containers:

$ docker network connect <network> <container>


To remove a container:

$ docker rm -f <container>

To remove all stopped containers:

$ docker container prune -f

To remove an image:

$ docker rmi -f <image>

To remove all unused images:

$ docker image prune --all -f

To clean up the system:

$ docker system prune -a

Building an Image

Creating a Dockerfile

FROM fedora:27
LABEL maintainer="Dogtag PKI Team <>"
ENV container=docker LANG=en_US.utf8 LANGUAGE=en_US.utf8 LC_ALL=en_US.utf8

RUN echo 'deltarpm = false' >> /etc/dnf/dnf.conf
RUN dnf update -y dnf
RUN dnf install -y dnf-plugins-core sudo wget
RUN dnf install -y python-srpm-macros
RUN dnf install -y @buildsys-build @development-tools

# Enable PKI COPR.
RUN dnf copr enable -y @pki/10.6
RUN dnf builddep -y pki-base

# Enable IPA COPR.
RUN dnf copr enable -y @freeipa/freeipa-4-6
RUN dnf install -y freeipa-server \
    freeipa-server-dns \
    freeipa-server-trust-ad \
    python-ipatests \
    --best --allowerasing

VOLUME ["/freeipa", "/run", "/tmp"]
ENTRYPOINT ["/usr/sbin/init"]

Building an image locally

To build an image from a Dockerfile:

$ docker build -t <image> <folder that contains Dockerfile>

Pushing an image to DockerHub

$ docker login --username=<username>
$ docker tag <image> <repo>/<username>/<image>:<tag>
$ docker push <repo><username>/<image>:<tag>

Building an image on DockerHub

VPN Issue

If /etc/resolv.conf is configured to use (e.g. due to VPN), Docker build may not work.


To fix the problem, find the actual DNS server:

$ nmcli dev show | grep IP4.DNS
IP4.DNS[1]:                             <DNS server>

Then edit /etc/sysconfig/docker-network and specify the following:


Then restart Docker:

$ systemctl restart docker

See also Containers cannot resolve DNS if docker host uses as resolver.