Build a Docker operating environment on AWS EC2, create an Apache HTTP Server container, and run it. Understand the basic operation of containers. (Pattern to operate after logging in to the container and pattern to use Docker File are implemented.)
--Docker server - EC2:t2.micro - OS:Red Hat Enterprise Linux 8 (HVM), SSD Volume Type --Disk: General-purpose SSD (GP2) 10GB
The security group settings are nice.
Follow the procedure below.
Log in to the Docker server with ec2-user
##Switch to root user
sudo su -
##Various library updates
dnf -y update
##Check the repository
dnf repolist
repo id repo name rhel-8-appstream-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI (RPMs) rhel-8-baseos-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI (RPMs) rhui-client-config-server-8 Red Hat Update Infrastructure 3 Client Configuration Server 8
##Add Docker repository
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
##Confirm that the repository has been added
dnf repolist
repo id repo name docker-ce-stable Docker CE Stable - x86_64 rhel-8-appstream-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI (RPMs) rhel-8-baseos-rhui-rpms Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI (RPMs) rhui-client-config-server-8 Red Hat Update Infrastructure 3 Client Configuration Server 8
##Check the existence of the Docker library to be installed
dnf info docker-ce
Last metadata expiration check: 0:00:54 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : docker-ce Epoch : 3 Version : 20.10.1 Release : 3.el8 Architecture : x86_64 Size : 27 M Source : docker-ce-20.10.1-3.el8.src.rpm Repository : docker-ce-stable Summary : The open-source application container engine URL : https://www.docker.com License : ASL 2.0 Description : Docker is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance and : everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider.
dnf info docker-ce-cli
Last metadata expiration check: 0:01:00 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : docker-ce-cli Epoch : 1 Version : 20.10.1 Release : 3.el8 Architecture : x86_64 Size : 33 M Source : docker-ce-cli-20.10.1-3.el8.src.rpm Repository : docker-ce-stable Summary : The open-source application container engine URL : https://www.docker.com License : ASL 2.0 Description : Docker is is a product for you to build, ship and run any application as a : lightweight container. : : Docker containers are both hardware-agnostic and platform-agnostic. This means : they can run anywhere, from your laptop to the largest cloud compute instance and : everything in between - and they don't require you to use a particular : language, framework or packaging system. That makes them great building blocks : for deploying and scaling web apps, databases, and backend services without : depending on a particular stack or provider.
dnf info containerd.io
Last metadata expiration check: 0:01:04 ago on Tue 29 Dec 2020 12:15:56 AM UTC. Available Packages Name : containerd.io Version : 1.4.3 Release : 3.1.el8 Architecture : x86_64 Size : 33 M Source : containerd.io-1.4.3-3.1.el8.src.rpm Repository : docker-ce-stable Summary : An industry-standard container runtime URL : https://containerd.io License : ASL 2.0 Description : containerd is an industry-standard container runtime with an emphasis on : simplicity, robustness and portability. It is available as a daemon for Linux : and Windows, which can manage the complete container lifecycle of its host : system: image transfer and storage, container execution and supervision, : low-level storage and network attachments, etc.
##Install Docker library
dnf -y install docker-ce docker-ce-cli containerd.io
##Docker service registration
systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
##Start Docker
systemctl start docker
##Docker startup confirmation
systemctl status docker
● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2020-12-29 00:19:07 UTC; 9s ago Docs: https://docs.docker.com Main PID: 58369 (dockerd) Tasks: 8 Memory: 59.2M CGroup: /system.slice/docker.service └─58369 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
##Docker version check
docker --version
Docker version 20.10.1, build 831ebea
##Run Hello World
docker run hello-world
`Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec 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:
##Check Docker image
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 12 months ago 13.3kB
##Download CentOS 8 image from Docker Hub
docker pull centos:centos8
centos8: Pulling from library/centos 7a0437f04f83: Pull complete Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1 Status: Downloaded newer image for centos:centos8 docker.io/library/centos:centos8
##That the Docker image has been added
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 12 months ago 13.3kB centos centos8 300e315adb2f 3 weeks ago 209MB
##Start CentOS container (Map 8080 port of OS to 80 port of container)
docker run --detach --name test --privileged --publish=8080:80 centos:centos8 /sbin/init
b25e9ef1d672f5e802eaa03983457c9730c9a5805a7d1abddb4ad9056ec15a01
##Make sure port 8080 is listening on a Docker container
netstat -nap | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 58798/docker-proxy
##Check the process status of the started container
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b25e9ef1d672 centos:centos8 "/sbin/init" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp test 28a9e2902746 hello-world "/hello" 9 minutes ago Exited (0) 9 minutes ago nervous_wilbur
Log in to the container
# docker exec -it test bash
Below, it is carried out while logged in to the container
##OS check of container
cat /etc/os-release
NAME="CentOS Linux" VERSION="8" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8"
##Check the kernel of the container
uname -a
Linux b25e9ef1d672 4.18.0-240.1.1.el8_3.x86_64 #1 SMP Fri Oct 16 13:36:46 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux
##Install Apache HTTP Server in a container
dnf install -y httpd
##Check the version of installed Apache HTTP Server
httpd -v
Server version: Apache/2.4.37 (centos) Server built: Nov 4 2020 03:20:37
##Apache HTTP Server service registration
systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
##Start Apache HTTP Server
systemctl start httpd
##Check the startup status of Apache HTTP Server
systemctl status httpd
##index.Creating html
vi /var/www/html/index.html
cat /var/www/html/index.html
<html>
<body>
Test Container HTML File
</body>
</html>
##Checking the operation of Apache HTTP Server in the container
curl -i http://localhost/
`HTTP/1.1 200 OK Date: Tue, 29 Dec 2020 00:38:51 GMT Server: Apache/2.4.37 (centos) Last-Modified: Tue, 29 Dec 2020 00:37:43 GMT ETag: "37-5b78f99486ca0" Accept-Ranges: bytes Content-Length: 55 Content-Type: text/html; charset=UTF-8
Test Container HTML File `Exit from the container with control + d (because it's a Mac)
Access the URL below from your PC browser and
Confirm that "This page is not working ec2-13-114-50-13.ap-northeast-1.compute.amazonaws.com did not send data. ERR_EMPTY_RESPONSE" is displayed.
http: //
Access the URL below from your PC browser and
Confirm that Test Container HTML File is displayed
http: //
##Stop container
docker stop b25e9ef1d672
b25e9ef1d672
##Delete container process
docker rm b25e9ef1d672
b25e9ef1d672
##Creating a directory for Docker File
mkdir -p docker/httpd
cd docker/httpd/
##Create Docker File (Install Apache HTTP Server and start httpd process when container starts. Index..Also create html. )
vi DockerFile
cat Dockerfile
# setting base image
FROM centos:centos8
# Auther
MAINTAINER MARTOON
# install Apache httpd server
RUN dnf install -y httpd
# create index.html
RUN echo "sample httpd container" > /var/www/html/index.html
# enable httpd
RUN systemctl enable httpd
# start httpd
CMD systemctl start httpd
##Build Docker Image from Docker File
docker build -t sample_httpd:0.1 .
##Confirmation of the existence of the built container image
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE sample_httpd 0.1 6892219088b3 24 seconds ago 250MB centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB
##Launch the built container image
docker run --detach --name sample_httpd --privileged --publish=8080:80 sample_httpd:0.1 /sbin/init
d7bd77d61494b97fa00c5664aed59d9080c0b1d210581b2c3a7732f1ab47c94b
Access the URL below from your PC browser and
Confirm that "This page is not working ec2-13-114-50-13.ap-northeast-1.compute.amazonaws.com did not send data. ERR_EMPTY_RESPONSE" is displayed.
http: //
Access the URL below from your PC browser and
Confirm that sample httpd container is displayed
http: //
##Check the Docker process
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d7bd77d61494 sample_httpd:0.1 "/sbin/init" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp sample_httpd
##Stop the started container
docker stop d7bd77d61494
d7bd77d61494
##Delete the started container
docker rm d7bd77d61494
d7bd77d61494
##Checking the container image
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE sample_httpd 0.1 8d1a1edebfdf 3 minutes ago 250MB centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB
##Delete the built container image
docker rmi 8d1a1edebfdf
##Confirm that the container image has been deleted
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE centos centos8 300e315adb2f 3 weeks ago 209MB hello-world latest bf756fb1ae65 12 months ago 13.3kB