In this tutorial we will learn how to move the first steps with Docker images by pulling and executing a Fedora Docker image. We will also learn how to check the active running Docker containers and their status.
Having installed Docker it’s time to run your first Docker image. Verify at first that Docker is running:
[[email protected] ~]$ sudo service docker status
Here is the output:
docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since ven 2015-09-18 16:03:40 CEST; 5min ago Docs: https://docs.docker.com Main PID: 3726 (docker) CGroup: /system.slice/docker.service └─3726 /usr/bin/docker daemon -H fd://
We will now pull and run a Fedora Docker image. Here ‘s how to do it:
$ sudo docker run -i -t fedora /bin/bash
A first check on the local repository will be performed. As we don’t have any image yet it will be downloaded:
Unable to find image 'fedora:latest' locally latest: Pulling from library/fedora 48ecf305d2cf: Pull complete ded7cd95e059: Pull complete library/fedora:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:49ae2d6d0b51f713a18db1c0da9fb1b5c94e92eb43cd712ba09028161ea22880 Status: Downloaded newer image for fedora:latest Now, once downloaded, the /bin/bash shell will be executed which will put us into the Fedora shell:
Now, once downloaded, the /bin/bash shell will be executed which will put us into the Fedora shell:
[[email protected] /]# id uid=0(root) gid=0(root) groups=0(root) [[email protected] /]# env HOSTNAME=73f9935376c5 TERM=xterm PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PWD=/ SHLVL=1 HOME=/root _=/usr/bin/env [[email protected] /]# pwd / [[email protected] /]# ls bin dev home lib64 media opt root sbin sys usr boot etc lib lost+found mnt proc run srv tmp var
If we open another shell, we can check the docker ps command which will show the active docker images:
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 73f9935376c5 fedora "/bin/bash" 6 minutes ago Up 6 minutes fervent_tesla
Another command you have to learn is docker images which shows the images you have downloaded so far:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE fedora latest ded7cd95e059 3 months ago 186.5 MB
When done, switch to the docker container and exit the shell:
[[email protected] /]# exit