1. What is Docker ?
Docker is a software package which is installed on a server or host OS and then provides a facility to create containers. Each container can contain an application and its required libraries & binaries.
In short, it provides virtualization at operating system level with very low requirement of system resources.
2. How to start with Docker ?
To start with docker first install docker version applicable to your operating system from here.
3. Check Installed Docker version and run first hello-world container image.
$ docker --version
Docker version 18.09.0, build 4d60db4
$ docker info
Server Version: 18.09.0
Storage Driver: overlay2
Backing Filesystem: extfs
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Status: Downloaded newer image for hello-world:latest
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
Share images, automate workflows, and more with a free Docker ID:
For more examples and ideas, visit:
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 2 days ago 1.84kB
$ docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1eb39ef342d8 hello-world "/hello" About an hour ago Exited (0) About an hour ago naughty_lichterman
4. Creating your container: By creating dockerfile.
a. Get docker Image
The first step is to identify the image by going to Docker HUB.
Go to Docker Hub and search for PHP. And then include the core image name to build your container.
b. Create our docker File
Now since we know the image from which we need to build the container. Lets create the docker file.
$ mkdir docker $ cat Dockerfile FROM php:7.2-apache COPY ./src /var/www/html/ EXPOSE 80 $ mkdir src; touch src/index.php $ cat src/index.php
c. Build the container.
### "php_container1" is any name given by us for the docker container. ### "." defines the location of docker file i.e. present directory. $ docker build -t php_container1 . Sending build context to Docker daemon 3.584kB Step 1/3 : FROM php:7.2-apache ---> 342a9fa6554c Step 2/3 : COPY ./src /var/www/html/ ---> 9b1c668c295a Step 3/3 : EXPOSE 80 ---> Running in 4bdab10e79b6 Removing intermediate container 4bdab10e79b6 ---> 581fbbf7642a Successfully built 581fbbf7642a Successfully tagged php_container1:latest $
d. Run our container.
$ docker run -p 80:80 php_container1 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Mon Jan 07 18:18:41.920513 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.13 configured -- resuming normal operations [Mon Jan 07 18:18:41.920604 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 172.17.0.1 - - [07/Jan/2019:18:18:55 +0000] "GET / HTTP/1.1" 200 245 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" 172.17.0.1 - - [07/Jan/2019:18:18:55 +0000] "GET /favicon.ico HTTP/1.1" 404 501 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" 172.17.0.1 - - [07/Jan/2019:18:19:09 +0000] "GET / HTTP/1.1" 200 245 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" Now open your browser and open localhost to see the php container.
Now we have a PHP Apache webserver running with the data we copied to the container.
Suppose you want to change the content, for this we need to rebuild this container. To avoid rebuilding container, we can mount a directory from local system to the docker container which we will look in the Part 2.