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 Dockerhtml
linux centos 7.6linux
If you have installed an older version of docker, you need to uninstall it firstnginx
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
install dependenciesdocker
sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
set stable Repositoryvim
sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
install dockercentos
sudo yum install docker-ce docker-ce-cli containerd.io
start docker serviceapp
sudo systemctl start docker
Run a demo to see if the installation was successfului
: The hello-world image is not in your local, but when you run the command, docker will pulls the helloworld image from the remote repositorycode
sudo docker run hello-world
create dockerfilehtm
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
vim Dockerfile
FROM nginx
MAINTAINER author <email>
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
:wq
build image
docker build -t test/hello-world: .
-t is to set the repository and image
test is repository name
hello-world as the image name
run image
docker run --name hello -d -p 8080:80 test/hello
Browser input http://localhost:8080/
This is a simple example of using Dockerfile to build the image and run the container!