===== Overview ===== How to install and test Docker and friends on current Fedora 29. Extra: * ''curl -fsSL get.docker.com -o get-docker.sh'' ===== Links ===== * [[https://docs.docker.com/]] * [[https://docs.docker.com/install/]] * [[https://docs.docker.com/install/linux/docker-ce/fedora/]] * [[https://docs.docker.com/install/linux/linux-postinstall/|Post-installation steps for Linux]] ===== Get rid of earlier Docker/container content ===== Fedora's Docker packaging has undergone some reorganization, so you first need to get rid of all earlier Docker-related packages. First, take a quick look at what Docker-related packages are already installed: $ rpm -qa "*docker*" docker-ce-17.12.1.ce-1.fc27.x86_64 python3-dockerpty-0.4.1-7.fc27.noarch docker-compose-1.17.1-1.fc27.noarch python3-docker-pycreds-0.2.1-5.fc27.noarch python3-docker-2.6.1-1.fc27.noarch $ If you see older packages, then remove them before going any further: $ sudo dnf remove \ docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine $ or possibly just: $ sudo dnf remove "*docker*" ===== Registering the Docker repository ===== The easiest way to install the new Docker packages for Fedora is to register the Docker repository containing those packages. First, install the DNF plugin to manage repositories from the command line: $ sudo dnf install dnf-plugins-core Next, register the Docker repository by running: $ sudo dnf config-manager \ --add-repo \ https://download.docker.com/linux/fedora/docker-ce.repo To verify that this worked, query that repo %%--%% you should see something like this: $ dnf repoquery --repo=docker-ce-stable containerd.io-0:1.2.2-3.fc29.x86_64 docker-ce-3:18.09.1-3.fc29.x86_64 docker-ce-cli-1:18.09.1-3.fc29.x86_64 $ ===== Installing Docker and Docker Compose ===== At this point, you can install Docker (and Docker Compose if you wish): $ sudo dnf install docker-ce [docker-compose] resulting in: Installing: containerd.io x86_64 1.2.2-3.fc29 docker-ce-stable replacing runc.x86_64 2:1.0.0-66.dev.gitbbb17ef.fc29 docker-ce x86_64 3:18.09.1-3.fc29 docker-ce-stable Installing dependencies: docker-ce-cli x86_64 1:18.09.1-3.fc29 docker-ce-stable libcgroup x86_64 0.41-20.fc29 fedora Should create group ''docker''. ===== Docker RPM scripts ===== ==== preinstall ==== if [ $1 -gt 0 ] ; then # package upgrade scenario, before new files are installed # clear any old state rm -f /var/lib/rpm-state/docker-is-active > /dev/null 2>&1 || : # check if docker service is running if systemctl is-active docker > /dev/null 2>&1; then systemctl stop docker > /dev/null 2>&1 || : touch /var/lib/rpm-state/docker-is-active > /dev/null 2>&1 || : fi fi ==== postinstall ==== if [ $1 -eq 1 ] ; then # Initial installation systemctl --no-reload preset docker &>/dev/null || : fi if ! getent group docker > /dev/null; then groupadd --system docker fi ... EE stuff snipped ... ==== preuninstall ==== if [ $1 -eq 0 ] ; then # Package removal, not upgrade systemctl --no-reload disable --now docker &>/dev/null || : fi update-alternatives --remove dockerd /usr/bin/dockerd || true ==== postuninstall ==== if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall systemctl try-restart docker &>/dev/null || : fi ===== Starting Docker ===== $ systemctl status docker.service ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: https://docs.docker.com $ $ sudo systemctl enable docker $ sudo systemctl start docker and verify that it's running with: $ systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2019-01-24 05:45:18 EST; 6s ago Docs: https://docs.docker.com Main PID: 16470 (dockerd) Tasks: 46 Memory: 58.3M CGroup: /system.slice/docker.service ├─16470 /usr/bin/dockerd -H fd:// └─16496 containerd --config /var/run/docker/containerd/containerd.toml --log-level info $ ===== Testing installation ===== $ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ $ ===== Running Docker as a non-root user ===== The installation of ''docker-ce'' should have created a new group named ''docker'', and if you want to run Docker images without the constant need for ''sudo'', simply add your username to that group: $ sudo usermod -aG docker your-username then log out and log in again, and verify that you're a member of the ''docker'' group with: $ id uid=1000(rpjday) gid=1000(rpjday) groups=1000(rpjday),967(docker) ... ^^^^^^ $ At this point, you should be able to run the Hello, World image without root privilege: $ docker run hello-world ... etc etc ... ===== Running Ubuntu bash ===== $ docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 38e2e6cd5626: Pull complete 705054bc3f5b: Pull complete c7051e069564: Pull complete 7308e914506c: Pull complete Digest: sha256:945039273a7b927869a07b375dc3148de16865de44dec8398672977e050a072e Status: Downloaded newer image for ubuntu:latest root@f7c76c6f0ee4:/# id uid=0(root) gid=0(root) groups=0(root) root@f7c76c6f0ee4:/# From another session: # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f7c76c6f0ee4 ubuntu "bash" 25 seconds ago Up 22 seconds nifty_spence