In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "Docker installation and basic command introduction". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
# install / start Docker
# install on CentOS 7
Docker is already included in the CentOS-Extra repository by default. Install it using the following command
Sudo yum install docker
# install on CentOS 6.5
For CentOS 6.5 Docker is part of the EPEL repository, so you need to make sure that you have joined the YUM source of EPEL. On CentOS 6, the package name of Docker may conflict with the docker application on the desktop, so its package name is changed to docker-io.
Sudo yum-y remove dockersudo yum install docker-io
# start Docker
After installing Docker, you need to start the Docker daemon
Sudo service docker start
In order for docker to boot and run, you need to use chkconfig: sudo chkconfig docker on
Get the Docker image and start the Docker container
Sudo docker pull centossudo docker images centossudo docker run-I-t centos / bin/bash
# basic commands
The following command creates a simple output Hello world for the container:
$docker run ubuntu:14.04 / bin/echo 'Hello, world'Hello, world
Here the docker run command specifies that the image to be used is ubuntu:14.04, from which our container runs. When specifying an image, Docker will first look for the existence of the image on your host machine, and download it from Docker Hub if it does not exist.
Next, you specify that the command to run in the container is / bin/echo 'Hello. When the container starts, Docker creates a new ubuntu 14.04 environment and executes the command in it. When the command is executed, the lifecycle of the container created by Docker ends.
Let's create an interactive container:
$docker run-t-I ubuntu:14.04 / bin/bashroot@af8bae53bdd3:/#
Mirroring of ubuntu 14.04 is also started this time, but two additional parameters-t and-I are specified here. The parameter-t assigns a pseudo terminal (pseudo-tty) to the container you just created, and-I allows us to create an interactive connection by getting the standard input of the container.
To exit the container, type exit or ctrl+D at the terminal so that the container can be stopped
Root@2e3e7e77adbd:/# exitexit
Several commonly used docker commands:
Docker ps lists Container
Standard output of docker logs display container
Container where docker stop stops running
Docker version displays version information of the current docker client and daemon
There are many subcommands of the docker command
Attach is attached to a running container build builds an image commit from the Dockerfile current modification of the container creates a new image cp copies files / folders from the container's file system to the host path create creates a new container diff checks the container file system changes events gets real-time events from the server exec already exists Run the command export in the container to stream the contents of the container to tar archive history display mirror history images list all mirrored import create a new file system image info display system information inspect returns container low-level information kill kills a running container load loads an image login from a tar archive Register or log in to the Docker registration server logout log out of the logs retrieval container from the Docker registration server port query based on the open port from NAT to PRIVATE_PORT pause pauses all processes in the container ps lists the container pull pulls an image from the Docker registration server or the warehouse push pushes an image or warehouse to the Docker registration server restart Restart a running container rm delete one / more container rmi delete one / more images run in the new container run the command save save image to tar archive search search for an image from Docker Hub start a stopped container stop stop running container tag tag the image in the repository top Query the process running in the container unpause cancel the paused status of the container version displays the version information of Docker wait is blocked until the container stops And then print its exit code.
Use Dockerfile to build the image:
Docker build-t /.
Run the image:
Docker run-p:-d curl-I:
View the container's log (similar to the tail-f command)
Docker logs-f
# example: use an official Nginx Docker image
You need to obtain the official nginx image before using it.
Docker pull nginx
Execute the command as follows
Docker run-- name nginx_server-d-p 8080VV / Users/mylxsw/codes/php:/usr/share/nginx/html:ro nginx
The parameters provided are explained one by one below:
Name specifies that the name of the container we created is nginx_server.
-d specifies that the container runs in the background
-p specifies that port 80 of the container is mapped to port 8080 of the host
The-v parameter specifies that the local / Users/mylxsw/codes/php directory is mapped to the container's / usr/share/nginx/html directory, and the access permission is read-only
Once the container is started, it can be accessed through http://localhost:8080.
To make it more complicated, you can specify the nginx configuration file-v / some/nginx.conf:/etc/nginx/nginx.conf:ro by using the-v argument.
When specifying a new nginx configuration file, be sure to set the daemon off; configuration item for nginx. If you run in background mode, the container will not be able to track the nginx process and will end immediately after the container starts.
If it's just a test, you can use the-- rm option so that it can be deleted automatically after the container finishes running, but not with the-d option, of course.
Docker run-- rm-- name nginx_server-d-p 8080 name nginx_server 80-v / Users/mylxsw/codes/php:/usr/share/nginx/html:ro nginx "introduction to Docker installation and basic commands" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.