Here is the commands to install docker to your server:
apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce -y
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 -y
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
You can verify the docker installation with:
docker version
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:11:19 2017
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:09:54 2017
OS/Arch: linux/amd64
Experimental: false
You can see all the docker images by searching by the name such as:
docker search apache
NAME DESCRIPTION STARS OFFICIAL
tomcat Apache Tomcat is an open source implementati… 1705 [OK]
httpd The Apache HTTP Server Project 1482 [OK]
cassandra Apache Cassandra is an open-source distribut… 722 [OK]
maven Apache Maven is a software project managemen… 543 [OK]
solr Solr is the popular, blazing-fast, open sour… 487 [OK]
We can pull the image by its name so that we have it locally.
docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
f49cf87b52c1: Pull complete
02ca099fb6cd: Pull complete
de7acb18da57: Pull complete
770c8edb393d: Pull complete
0e252730aeae: Pull complete
6288e83d58fa: Pull complete
a91ad03b2178: Pull complete
Digest: sha256:643ca2ed9f6caf1f392184aee05a8f2cd478bdacbd350ea6b4dbc8f5b8e400a8
Status: Downloaded newer image for httpd:latest
To run the web server we need to use the run command.
docker run -d -p 80:80 --name website httpd
The name we will give this web server is website.
We can check the container running with docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe844be6b6cd httpd "httpd-foreground" 8 seconds ago Up 6 seconds 0.0.0.0:80->80/tcp website
If we no longer want to run the web server we can stop it with:
docker stop website