preface
This article only explains the installation of Docker and the creation of Dockerfile. Dockerfile is composed of different commands in different requirements, which can be understood as a configuration file. However, only a demo is shown here to show the basic usage of Docker
Server environment
install
- step 1
If you have installed an older version of docker, you need to uninstall it first
1 | sudo yum remove docker \ |
- step 2
install dependencies
1 | sudo yum install -y yum-utils \ |
- step 3
set stable Repository
1 | sudo yum-config-manager \ |
- step 4
install docker
1 | sudo yum install docker-ce docker-ce-cli containerd.io |
- step 5
start docker service
1 | sudo systemctl start docker |
- step 6
Run a demo to see if the installation was successful
: The hello-world image is not in your local, but when you run the command, docker will pulls the helloworld image from the remote repository
1 | sudo docker run hello-world |
create a demo
- step 1
create dockerfile
Choose any directory and create a dockerfile.
It is suggested to name ‘Dockerfile’, because by default docker will run the file called ‘Dockerfile’ in the current directory. If you give it a different name, add the -f parameter and the path of the dockerfile
1 | vim Dockerfile |
- step 2
build image
1 | docker build -t test/hello-world: . |
-t is to set the repository and image
test is repository name
hello-world as the image name
- step 3
run image
1 | docker run --name hello -d -p 8080:80 test/hello |
- step 4
Browser input http://localhost:8080/
final
This is a simple example of using Dockerfile to build the image and run the container!