Setup docker lên centos 7 và dùng docker compose tạo hello world với apache
Link setup của docker:https://docs.docker.com/engine/install/centos/
Phần 1:Setup docker lên centos 7
1.1 Update and Install Dependencies:
sudo yum update -y
1.2 Set up the repository
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
1.3 Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
1.4 Start Docker.
sudo systemctl start docker
To enable Docker to start on boot, use the following command:
sudo systemctl enable docker
1.5 Test
sudo docker run hello-world
Thấy kết quả sau là thành công:
Phần 2:Tạo hello world
2.1 Create a directory
Create a new directory for your project.
This will be the root of your Docker Compose application.
cd /home
mkdir hello-apache
cd hello-apache
2.2 Create a file named docker-compose.yaml in the directory
version: "3.8"
services:
web:
image: httpd:latest
volumes:
- /home/hello-apache/index.html:/usr/local/apache2/htdocs/index.html:ro
ports:
- "80:80"
2.3 Create file index.html in folder /home/hello-apache with content
Hello, world
2.4 .Build and run the application:
docker compose up -d
2.5 Test
Truy cập browser với url:yourip Ví dụ: http://192.168.64.128
Một số lệnh cơ bản dùng trong bài viết:
To stop the container and remove its resources, run the following command:
docker compose down
Kiểm tra có các container nào đang chạy:
docker ps -a
Remove container đang chạy
docker rm -f containerid
All rights reserved