Docker Back

Othere Languages
Menu
- 1. Install
- 2. About images & containers
- 3. About finding the whalesay image
- 4. About building an image
- 5. About creating a repository
- 6. Tag, push and pull images
1. Install
- i. Log into your Ubuntu installation as a user with
sudoprivileges. ii. Verify that you have
wgetinstalled.- Check
$ which wget - If
wgetisn't installed, install it after updating your manager:$ sudo apt-get update $ sdo apt-get install wget
- Check
iii. Get the latest Docker package.
- The system prompts you for your
sudopassword. Then, it downloads and installs Docker and its dependencies.$ wget -q0- https://get.docker.com/ | sh - Note1: If your company is behind a filtering proxy, you may find that the
apt-keycommand fails for the Docker repo during installation. To work around this, add the key directly using the following:$ wget -qO- https://get.docker.com/gpg | sudo apt-key add - - Note2: Docker currently only supports 64bit platforms.
- The system prompts you for your
iv: Verify
dockeris installed correctly:$ docker run hello-worldUnable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 535020c3e8ad: Pull complete af340544ed62: Pull complete Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c Status: Downloaded newer image for hello-world:latest- The following message shows that your installation appears to be working correctly.
Hello from Docker. To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub.
- The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
- 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 Hub account: https://hub.docker.com
- For more examples and ideas, visit: https://docs.docker.com/userguide/
- The following message shows that your installation appears to be working correctly.
2. About images & containers
- As the last step in your installation, you ran the docker run
hello-worldcommand. With this one command, you completed the core tasks to using Docker. The command you ran had three parts.

- A container: A container is a stripped-to-basics version of a Linux operating system.
- An image: An image is software you load into a container.
- When you ran the command, the Docker software:
- checked to see if you had the
hello-wordsoftware image - downloaded the image from the Docker Hub (more about the hub later)
- loaded the image into the container and “ran” it
- checked to see if you had the
- Depending on how it was built, an image might run a simple, single command and then exit. This is what
hello-worlddid. - A Docker image, though, is capable of much more. An image can start software as complex as a database, wait for you (or someone else) to add data, store the data for later use, and then wait for the next person.
- Who built the
hello-worldsoftware image though? In this case, Docker did but anyone can. Docker lets people (or companies) create and share software through Docker images. Using Docker, you don't have to worry about whether your computer can run the software in a Docker image — a Docker container can always run it.
3. About finding the whalesay image
- People all over the world create Docker images. You can find these images by browsing the Docker Hub.
Step1: Locate the whalesay image
- i. Open your browser and browse to the Docker Hub.
- The Docker Hub contains images from individuals like you and official images from organizations like RedHat, IBM, Google, and a whole lot more.
- ii. Click Browser & Search.
- iii. Enter the word
whalesayin the search bar. - iv. Click on the
docker/whalesayimage in the results.- Each image repository contains information about an image. It should include information such as what kind of software the image contains and how to use it. You may notice that the whalesay image is based on a Linux distribution called Ubuntu. In the next step, you run the whalesay image on your machine.
Step2: Run the Whalesay image
- i. Call the following comand in the terminal:
- The first time you run a software image, the
dockercommand looks for it on your local system. If the image isn't there, thendockergets it from the hub.$ docker run docker/whalesay cowsay boo
- The first time you run a software image, the
- ii. Find what images you have by calling the following command:
- When you run an image in a container, Docker downloads the image to your computer. This local copy of the image saves you time. Docker only downloads the image again if the image's source changes on the hub. You can, of course, delete the image yourself. (You'll learn more about that later)
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker/whalesay latest fb434121fc77 3 hours ago 247 MB hello-world latest 91c95931e552 5 weeks ago 910 B
- When you run an image in a container, Docker downloads the image to your computer. This local copy of the image saves you time. Docker only downloads the image again if the image's source changes on the hub. You can, of course, delete the image yourself. (You'll learn more about that later)
4. About building an image
Step1: Write a Dockerfile
i. Make a new directory:
$ mkdir mydocker buildii. Create a text file called
Dockerfilein te new directory:- A Dockerfile describes the software that is “baked” into an image. It isn't just ingredients tho, it can tell the software what environment to use or what commands to run. Your recipe is going to be very short.
$ cd mkdocker $ vim Dockerfile
- A Dockerfile describes the software that is “baked” into an image. It isn't just ingredients tho, it can tell the software what environment to use or what commands to run. Your recipe is going to be very short.
- iii. Add a line to the text file:
- The FROM keyword tells Docker which image your image is based on. Whalesay is cute and has the
cowsayprogram already, so we'll start there.FROM docker/whalesay:latest
- The FROM keyword tells Docker which image your image is based on. Whalesay is cute and has the
- iv. Add the
fortunesprograme to the image:- The
fortunesprogram has a command that prints out wise sayings for our whale to say. So, the first step is to install it. This line installs the software into the image.RUN apt-get -y update && apt-get install -y fortunes
- The
- v. Once the image has the software it needs, you instruct the software to run when the image is loaded:
- This line tells the
fortuneprogram to pass a nifty quote to thecowsayprogram.CMD /usr/games/fortune -a | cowsay
- This line tells the
- vi. Save and close the text file.
- At this point, you have all your software ingredients and behaviors described in a Dockerfile. You are ready to build a new image
Step2: Build an image from your Dockerfile
Now, build your new image by typing the
docker build -t docker-whale .command in your terminal (don't forget the . period). (This proccess will take several seconds to run and reports its outcomd)Sending build context to Docker daemon 158.8 MB ...snip... Removing intermediate container a8e6faa88df3 Successfully built 7d9495d03763
Step3: Learn about the build process
- The
docker build -t docker-whale .command takes theDockerfilein the current directory, and builds an image calleddocker-whaleon your local machine. The command takes about a minute and its output looks really long and complex. In this section, you learn what each message means. First Docker checks to make sure it has everything it needs to build.
Sending build context to Docker daemon 158.8 MBThen, Docker loads with the
whalesayimage. It already has this image locally as your might recall from the last page. So, Docker doesn't need to download it.Step 0 : FROM docker/whalesay:latest ---> fb434121fc77Docker moves onto the next step which is to update the
apt-getpackage manager. This takes a lot of lines, no need to list them all again here.Step 1 : RUN apt-get -y update && apt-get install -y fortunes ---> Running in 27d224dfa5b2 Ign http://archive.ubuntu.com trusty InRelease Ign http://archive.ubuntu.com trusty-updates InRelease Ign http://archive.ubuntu.com trusty-security InRelease Hit http://archive.ubuntu.com trusty Release.gpg ....snip... Get:15 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [14.8 kB] Get:16 http://archive.ubuntu.com trusty-security/universe amd64 Packages [134 kB] Reading package lists... ---> eb06e47a01d2Then, Docker installs the new
fortunessoftware.Removing intermediate container e2a84b5f390f Step 2 : RUN apt-get install -y fortunes ---> Running in 23aa52c1897c Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: fortune-mod fortunes-min librecode0 Suggested packages: x11-utils bsdmainutils The following NEW packages will be installed: fortune-mod fortunes fortunes-min librecode0 0 upgraded, 4 newly installed, 0 to remove and 3 not upgraded. Need to get 1961 kB of archives. After this operation, 4817 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main librecode0 amd64 3.6-21 [771 kB] ...snip...... Setting up fortunes (1:1.99.1-7) ... Processing triggers for libc-bin (2.19-0ubuntu6.6) ... ---> c81071adeeb5 Removing intermediate container 23aa52c1897cFinally, Docker finishes the build and reports its outcome
Step 3 : CMD /usr/games/fortune -a | cowsay ---> Running in a8e6faa88df3 ---> 7d9495d03763 Removing intermediate container a8e6faa88df3 Successfully built 7d9495d03763
Step 4: Run your new docker-whale
i. Check the new image you created:
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker-whale latest 7d9495d03763 4 minutes ago 273.7 MB docker/whalesay latest fb434121fc77 4 hours ago 247 MB hello-world latest 91c95931e552 5 weeks ago 910 Bii. Run your new image by typing
docker run docker-whale:$ docker run docker-whale
5. About creating a repository
Step 1: Sign up an acount on Docker Hub
Step 2: Verify your email and add a repository
6. Tag, push and pull images
Step 1: Tag and push the image
i. List the images you currently have:
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB <none> <none> 5dac217f722c 45 minutes ago 273.7 MB docker/whalesay latest fb434121fc77 4 hours ago 247 MB hello-world latest 91c95931e552 5 weeks ago 910 Bii. Find the
IMAGE IDfor yourdocker-whaleimage.- In this case, the id is
7d9495d03763. - You'll notice that currently, the
REPOSITORYshows the repository but not the namespace fordocker-whale. You need to include thenamespacefor Docker Hub to associate it with your account. Thenamespaceis the same as your account name.
- In this case, the id is
- iii. Use
IMAGE IDand thedocker tagcommand to tag yourdocker-whaleimage.

iii. Type the
docker imagescommand again to see your newly tagged image.$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE maryatdocker/docker-whale latest 7d9495d03763 5 minutes ago 273.7 MB docker-whale latest 7d9495d03763 2 hours ago 273.7 MB <none> <none> 5dac217f722c 5 hours ago 273.7 MB docker/whalesay latest fb434121fc77 5 hours ago 247 MB hello-world latest 91c95931e552 5 weeks ago 910 Biv. Use the
docker logincommand to log into the Docker Hub from the command line.docker login --username=yourhubusername --password=yourpassword --email=youremail@company.comv. Type the
docker pushcommand to push your image to your new repository.$ docker push maryatdocker/docker-whale The push refers to a repository [maryatdocker/docker-whale] (len: 1) 7d9495d03763: Image already exists c81071adeeb5: Image successfully pushed eb06e47a01d2: Image successfully pushed fb434121fc77: Image successfully pushed 5d5bd9951e26: Image successfully pushed 99da72cfe067: Image successfully pushed 1722f41ddcb5: Image successfully pushed 5b74edbcaa5b: Image successfully pushed 676c4a1897e6: Image successfully pushed 07f8e8c5e660: Image successfully pushed 37bea4ee0c81: Image successfully pushed a82efea989f9: Image successfully pushed e9e06b06e14c: Image successfully pushed Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
Step 2: Pull a new image
- In this last section, you'll pull the image you just pushed to hub. Before you do that though, you'll need to remove the original image from your local machine. If you left the original image on your machine. Docker would not pull from the hub — why would it? The two images are identical.
i. Use the
docker rmito remove themaryatdocker/docker-whaleanddocker-whaleimages.- You can use an ID or the name to remove an image.
$ docker rmi -f 7d9495d03763 $ docker rmi -f docker-whale
- You can use an ID or the name to remove an image.
ii. Pull a new image from your repository using the
docker pullcommand.- The command you type should include your username from Docker Hub.
$ docker pull yourusername/docker-whale
- The command you type should include your username from Docker Hub.
As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.
Notice: This plugin has used Cookie to store your token with an expiration.