• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SMASHING LAB

Guides | LINUX | GEEKY STUFF

  • Nginx
  • Linux
  • Guide
  • Ubuntu
  • WordPress
  • Drones, My Hobby

Deploy Your First Docker Container

By Imran Yousaf

The command docker runserves to launch Docker containers from images.

In this article, We’ll show you how to run a container from an image using the example of the latest official base Docker image of Ubuntu.

We’ll show you how to install apache2inside a container with Ubuntu and how to save this container as a new image.

And in the end, you will be able to run containers from this new image in the interactive and background modes.

Good advice: An image vs. Container … What’s the difference? Read More →

Running the Container from the Image into the Docker

Do not Confuse: The Docker image itself cannot be “run”. The command docker runtakes the Docker image as a template and creates a container from it, which is launched.

Locate the required image on the Docker Hub :

$ docker search ubuntu
NAME                            DESCRIPTION             STARS  OFFICIAL  AUTOMATED
ubuntu                          Ubuntu is a Debian...   6759   [OK]       
dorowu/ubuntu-desktop-lxde-vnc  Ubuntu with openss...   141              [OK]
rastasheep/ubuntu-sshd          Dockerized SSH ser...   114              [OK]
ansible/ubuntu14.04-ansible     Ubuntu 14.04 LTS w...   88               [OK]
ubuntu-upstart                  Upstart is an even...   80     [OK]

Download the Docker image from the repository using the command docker pull:

$ docker pull ubuntu

Start the container from the Docker image:

$ docker run -it ubuntu / bin / bash
root @ e785d56f4312: / #

When you execute Docker run image, the Docker engine takes image, adds the writeable top layer and initializes various parameters (network ports, container name, identifier and resource limits).

Install the Web server apache2inside the container, and then exit it:

root @ e785d56f4312: / # apt update
root @ e785d56f4312: / # apt install apache2 -y
root @ e785d56f4312: / # exit

From the stopped container in which you installed apache2, create a new image and name it apache_snapshot:

$ docker commit e785d56f4312 apache_snapshot

To view all the images on the Docker host:

$ docker images
REPOSITORY          TAG           IMAGE ID            CREATED             SIZE
apache_snapshot     latest        13037686eac3        22 seconds ago      249MB
ubuntu              latest        00fd29ccc6f1        3 weeks ago         111MB

Now from the new Docker-image, you can start the containers in interactive mode:

$ docker run -i -t apachesnapshot /bin/bash

Alternatively, you can run the container from the Docker image in the background with the port :80inside the Docker container flown to the :8080Docker host port :

$ docker run -d -p 8080:80 apache snapshot /usr/sbin/apache2ctl -D FOREGROUND

In this case, to make sure that apache2inside the container is running, simply open http://localhost:8080/ and you will see the start page: “Apache2 Ubuntu Default Page”.

Download WordPress Themes
Download Best WordPress Themes Free Download
Free Download WordPress Themes
Download WordPress Themes Free
lynda course free download
download micromax firmware
Download WordPress Themes
Tweet
Pin
Share
0 Shares

Some more articles you might also be interested in …

  • Install Docker in CentOS 7
  • Install Docker on Ubuntu 16.04 Xenial Xerus

Filed Under: Docker, Guide

Primary Sidebar

  • Twitter
  • Facebook
  • Google+

Recent Posts

  • What is a DNS attack and how does it work?
  • SSH (Part 2): Setting Up an OpenSSH Server
  • How to Use Systemctl to Manage Systemd Services
  • SSH (Part 1): What is SSH. SSH Utilities
  • 19 Useful Features of the .htaccess File

Subscribe to our Newsletter

Useful articles, tips and videos about creating and promoting websites to your mail



* required field




Partner

  • Contact Us
  • Privacy Policy
  • About Us

Copyright © 2019. Smashing Lab