Docker install and first Dockerfile
文章目录
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
linux centos 7.6
install
- step 1
If you have installed an older version of docker, you need to uninstall it first
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
- step 2
install dependencies
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
- step 3
set stable Repository
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- step 4
install docker
sudo yum install docker-ce docker-ce-cli containerd.io
- step 5
start docker service
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
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
vim Dockerfile
FROM nginx
MAINTAINER author <email>
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
:wq
- step 2
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
- step 3
run image
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!
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论