How to install Docker and run Docker containers on Fedora 25

Docker logo

Docker is an open source project supported by a commercial entity of the same name that makes it super-easy to run an application process inside a relatively isolated environment called a container. Unlike a virtual machine (VM), which has its own kernel, a container is dependent on the host operating system’s kernel.

As a result, it’s much lighter and boots up much faster. It’s the simplest tool that puts enterprise-class application deployment and management capabilities right on your desktop (laptop). By default, Docker containers are run using application images hosted on Docker Hub.

In this article, we’ll go through the process of installing and using it to run containers on any desktop flavor of Fedora 25.

Install Docker on Fedora 25

Every task will be completed from the command line, so fire up a terminal emulator. The latest version of Docker is in the Fedora official repository, so all you need to install Docker is type the following command:

# Installing Docker on Fedora 25

sudo dnf install docker

#

That installs the latest Docker Engine (version 1.12.3), which consists of the Docker daemon and Docker client. Because one needs the other to do anything useful, you first need to start the daemon and configure the system to start it every time the computer is (re)booted. The following pair of commands will accomplish that.

# Start the Docker daemon

sudo systemctl start docker

# Enable Docker to start on boot

sudo systemctl enable docker

#

Run Docker Containers on Fedora 25

The Docker daemon is now up and running, so you can run your first container. By default, the Docker is pointed to Docker Hub, which holds hundreds (perhaps thousands) of images waiting to be used to run containers. But let’s start by running the famous Hello World of the (Docker) container universe.

# Run your first Docker container

sudo docker run hello-world

#

The container will run and exit, because that’s how it was configured to behave. In the output, you’ll see lines like those below.

# Output of running a Docker container

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.
 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

#

The above output tells you each step involved, and what else you can run, so let’s try running the suggested container, using an official Ubuntu image. Unlike the first container you just ran, this one will not exit soon after running. Instead, the command will run the container, keep it running, and give you interactive tty access inside it, with the Bash shell.

# Run your first Docker container

sudo docker run -it ubuntu bash

#

What I’m sure you observed with that container is how fast it took to start. As noted earlier, that’s one difference between a software container and a virtual machine instance – speed. Containers boot up really, really fast. And they can be killed just as quickly.

Related Post:  Using New Relic, Splunk, Netuitive and AppDynamics for Container Monitoring

You’ll notice that your command prompt has changed to something like root@131a58505d2d:/#, where the string after the @ sign is the unique id of the container. So your host machine is powered by your favorite desktop flavor of Fedora 25, but you’re now operating from inside an Ubuntu container.

With command line access inside the container, you can do anything you want, like just exit the container, or do somethings more interesting, like update the package database, upgrade the system, and install any software you feel like installing. Note that because you’re operating from inside Ubuntu, the package management command is apt, not dnf. For now, you may exit the container by typing exit. In a future article, we’ll go into details of how to install applications inside a container, commit the changes, and push the new image derived from that to Docker Hub.

Let’s end this by running another container using the official Nginx image. By default, running the Nginx container will expose its ports 80 (http) and 443 (https). What this command does is map port 80 on the host machine to the equivalent port inside the container.

# Run Nginx container

sudo docker run -p 80:80 nginx

# Alternatively, you can force the container to detach by running this command

sudo docker run -d -p 80:80 nginx

#

Mapping the port in that fashion makes it possible to access the default Nginx page by pointing your browser to the host machine’s IP address. If you did that, you should see the default Nginx page, and if you ran the command without the -d option, you should see some output indicating that the page has been accessed.

Related Post:  Using Ansible with Docker to Deploy a WordPress Service on Rancher

Depending on the host machine’s resources, you can run as many containers as you want – at the same time. To search for images available on Docker Hub that you may use to run containers, type the following command:

# To search for an image on Docker Hub

sudo docker search 

# For example, to search for a Redis image

sudo docker search redis

#

Clean Up After Yourself

Whenever you run a container, the Docker client has to download an image from (by default) Docker Hub. The images are stored on your computer, and will remain there even after you’ve stopped or killed the container. With time, those images can take up a significant chunk of your computer’s storage space.

So a good habit to adopt is to delete those images you’ll not be using anytime soon. To list the images stored on your computer, type:

# Listing Docker images

sudo docker images

#

You should get an output like the following:

# Listing Docker images

REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
sematext/sematext-agent-docker   swarm3k             d0b840c91025        6 weeks ago         146.5 MB
alpine                           latest              4e38e38c8ce0        5 months ago        4.799 MB
cassandra                        latest              075b7d5e2ed5        5 months ago        385.2 MB
nginx                            latest              0d409d33b27e        6 months ago        182.8 MB
finid/ubuntu-nodejs              latest              925bbd11e0d7        6 months ago        206.7 MB
finid/ubuntu-nodejs              v2                  5a33c83a0835        6 months ago        206.6 MB
ubuntu-do                        latest              62359544c9ba        6 months ago        206.6 MB
ubuntu                           latest              c5f1cf30c96b        7 months ago        120.8 MB
hello-world                      latest              94df4f0ce8a4        7 months ago        967 B
redis                            latest              0f0e96f1f267        7 months ago        177.5 MB
swarm                            latest              0f1a3829719c        7 months ago        18.71 MB

#

Don’t think you’ll be needing an image anytime soon? Delete it:

# Deleting Docker images

sudo docker rmi 

# For example, to delete the Cassandra image shown in the previous output, type:

sudo docker rmi cassandra

#

Note that a container image can be deleted only if no container is using it, so if you get an error after attempting to delete an image, first stop and/or delete the container.

Running individual Docker containers like you just read in this article is fun, but that’s just the beginning. Docker has built-in support for load balancing, orchestration, service discovery and a host of other features. I’ll be exploring those in future articles. More on Docker here

Fedora 25 GNOME 3 applications

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn

Hola! Did you notice that LinuxBSDos.com no longer run network ads?  Yep, no more ads from the usual suspects that track and annoy you across the Internet. But since I still need to pay to keep the site running, feel free to make a small donation by PayPal or your favorite cryptocurrency.

  • Bitcoin
  • Ethereum
  • Xrp
  • Bitcoin cash
  • Bitcoin sv
  • Litecoin
  • Binance coin
  • Cardano
  • Ethereum classic
Scan to Donate Bitcoin to bc1qzvlte2m224zkayhdc7fdfjkp2rsgt0l5a496ua

Donate Bitcoin to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin

Scan to Donate Ethereum to 0x0F4362DFF77F3Ba0Dc637F5f3Eba35D09a2fA60C

Donate Ethereum to this address

Scan the QR code or copy the address below into your wallet to send some Ethereum

Scan to Donate Xrp to r4ggjvL36njsMCYTkJ3S7cTHscPsMsSGQv

Donate Xrp to this address

Scan the QR code or copy the address below into your wallet to send some Xrp

Scan to Donate Bitcoin cash to qrs0dedzp9t55af3nfwypydghp29r0xguy9s20fz2k

Donate Bitcoin cash to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin cash

Scan to Donate Bitcoin sv to 15K9TLyVDBtLuG9cYvXCX9SSkq9C9oUKHK

Donate Bitcoin sv to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin sv

Scan to Donate Litecoin to LetJ9QQMb7u2LMZ9Tu6rtHwcBcQFW98fbG

Donate Litecoin to this address

Scan the QR code or copy the address below into your wallet to send some Litecoin

Scan to Donate Binance coin to bnb1ga8trq08ssqepd90v6225nzfgy448pu5pw8gxp

Donate Binance coin to this address

Scan the QR code or copy the address below into your wallet to send some Binance coin

Scan to Donate Cardano to addr1qx2354yw49etstfljpdhwja3ajjlt487lg95vu9ngy2q6vu4rf2ga2tjhqknlyzmwa9mrm997h20a7stgectxsg5p5esq5l7d9

Donate Cardano to this address

Scan the QR code or copy the address below into your wallet to send some Cardano

Scan to Donate Ethereum classic to 0xcD6CC972a2297FcafACDcfE042C55C69516a9264

Donate Ethereum classic to this address

Scan the QR code or copy the address below into your wallet to send some Ethereum classic

Subscribe for updates. Trust me, no spam!

Sponsored links

1. Attend Algorithm Conference, a top AI and ML event.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.

Upcoming events

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest

On social media
Via my newsletter

Partner links

1. Attend Algorithm Conference, a top AI and ML event for 2021.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.
Hacking, pentesting distributions

Linux Distributions for Hacking

Experts use these Linux distributions for hacking, digital forensics, and pentesting.

Categories
Archives

The authors of these books are confirmed to speak during

Algorithm Conference

T-minus AI

Author was the first chairperson of AI for the U.S. Air Force.

The case for killer robots

Author is the Director of the Center for Natural and Artificial Intelligence.

Why greatness cannot be planned

Author works on AI safety as a Senior Research Scientist at Uber AI Labs.