Documente Academic
Documente Profesional
Documente Cultură
DockerHub is a cloud-based repository run and managed by Docker Inc. It's an online repository where Docker
images can be published and used by other users. There are both public and private repositories. If you are a
company, you can have a private repository for use within your own organization, whereas public images can
be used by anyone.
You can also use official Docker images that are published publicly. I use many such images, including for my
test WordPress installations, KDE plasma apps, and more. Although we learned last time how to create your
own Docker images, you don't have to. There are thousands of images published on DockerHub for you to use.
DockerHub is hardcoded into Docker as the default registry, so when you run the docker pull command against
any image, it will be downloaded from DockerHub.
$ docker images
This command will show all the docker images currently on your system. Let's say you want to deploy Ubuntu
on your local machine; you would do:
root@1b3ec4621737:/#
Now you can run any command and utility that you use on Ubuntu. It's all safe and contained. You can run all
the experiments and tests you want on that Ubuntu. Once you are done testing, you can nuke the image and
download a new one. There is no system overhead that you would get with a virtual machine.
$ exit
Now let's say you want to install Nginx on your system. Run search to find the desired image:
$ docker images
Now, suppose you want to push the ng image to DockerHub. First, we need to tag that image (learn more about
tags):
12628b20827e: Pushed
Learn more about Linux through the free "Introduction to Linux" course from The Linux Foundation and edX.
Learn the basic steps for creating Docker images in this tutorial.
Creative Commons Zero
Pixabay
In the previous article, we learned about how to get started with Docker on Linux, macOS, and
Windows. In this article, we will get a basic understanding of creating Docker images. There are
prebuilt images available on DockerHub that you can use for your own project, and you can publish
your own image there.
We are going to use prebuilt images to get the base Linux subsystem, as it’s a lot of work to build
one from scratch. You can get Alpine (the official distro used by Docker Editions), Ubuntu,
BusyBox, or scratch. In this example, I will use Ubuntu.
Before we start building our images, let’s “containerize” them! By this I just mean creating
directories for all of your Docker images so that you can maintain different projects and stages
isolated from each other.
$ mkdir dockerprojects
cd dockerprojects
Now create a Dockerfile inside the dockerprojects directory using your favorite text editor; I prefer
nano, which is also easy for new users.
$ nano Dockerfile
And add this line:
FROM Ubuntu
Save it with Ctrl+Exit then Y.
Now create your new image and provide it with a name (run these commands within the same
directory):
---> 2a4cca5ac898
Let’s check all the Docker images you have in your directory:
$docker images
Dockerfile is basically a set of instructions to install all the needed packages, configure, and copy
files. In this case, it’s Apache and Nginx.
You may also want to create an account on DockerHub and log into your account before building
images, in case you are pulling something from DockerHub. To log into DockerHub from the
command line, just run:
$ docker login
Enter your username and password and you are logged in.
$ nano Dockerfile
And paste these lines:
FROM ubuntu
RUN apt-get update && apt-get install -y apache2 && apt-get clean
&& rm -rf /var/lib/apt/lists/*
EXPOSE 80
It will take some time, then you should see successful build like this:
a189a4db0f7c245dd6c934ef7164f3ddde09e1f3018b5b90350df8be85c8dc98
Eureka. Your container image is running. Check all the running containers:
$ docker ps
To learn more, you can open your web browser and check out the documentation about how to
build more complicated Docker images like the whole LAMP stack. Here is a Dockerfile file for
you to play with. In the next article, I’ll show how to push images to DockerHub.
Learn more about Linux through the free "Introduction to Linux" course from The Linux
Foundation and edX.
The greatest thing about Docker containers is that you can use your local machine for development
and testing. The container images that you create on your local system can then run “anywhere.”
There is no conflict between developers and operators about apps running fine on development
systems but not in production.
The point is that in order to create containerized applications, you must be able to run and create
containers on your local systems.
You can use any of the three platforms -- desktop Linux, Windows, or macOS as the development
platform for containers. Once Docker is successfully running on these systems, you will be using
the same commands across platforms so it really doesn’t matter which OS you are running
underneath.
There are two channels of Docker CE: stable and edge. As the name implies, the stable version
gives you well-tested quarterly updates, whereas the edge version offers new updates every month.
After further testing, these edge features are added to the stable release. I recommend the stable
version for new users.
Docker CE is supported on macOS, Windows 10, Ubuntu 14.04, 16.04, 17.04 and 17.10; Debian
7.7,8,9 and 10; Fedora 25, 26, 27; and centOS. While you can download Docker CE binaries and
install on your Desktop Linux systems, I recommend adding repositories so you continue to receive
patches and updates.
Ubuntu Installation
First things first. Run a system update so your Ubuntu packages are fully updated:
$ groups swapnil
(Here, Swapnil is the user.)
$ docker info
Install Docker CE on macOS and Windows
You can easily install Docker CE (and EE) on macOS and Windows. Download the official Docker
for Mac and install it the way you install applications on macOS, by simply dragging them into the
Applications directory. Once the file is copied, open Docker from spotlight to start the installation
process. Once installed, Docker will start automatically and you can see it in the top bar of macOS.
macOS is UNIX, so you can simply open the terminal app and start using Docker commands
natively. Test the hello world app:
Docker on Windows 10
You need the latest version of Windows 10 Pro or Server in order to run/install Docker on it. If you
are not fully updated, Windows won’t install Docker. I got an error on my Windows 10 system and
had to run system updates. My version was still behind, and I hit this bug. So, if you fail to install
Docker on Windows, just know you are not alone. Keep an eye on that bug to find a solution.
Once you install Docker on Windows, you can either use bash shell via WSL or use PowerShell to
run docker commands. Let’s test the “Hello World” command in PowerShell:
In the next article, we will talk about pulling images from DockerHub and running containers on
our systems. We will also talk about pushing our own containers to Docker Hub.
Learn more about Linux through the free "Introduction to Linux" course from The Linux Foundation
and edX.