In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Archlinux in the first container how to create, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1. Run the following command to create our first container sudo docker run-I-t base/archlinux / bin/bash# if you need to use ubuntu image sudo docker run-I-t ubuntu / bin/bash# if you need to use centOS image sudo docker run-I-t centos / bin/bash# if you need to use centOS7 image sudo docker pull openshift/base-centos7 / bin/bash
However, the following exception may occur. If this exception occurs, you can try to change the source or pull the image locally through docker pull.
If there is no exception, enter our first container
The-I in the command ensures that the STDIN in the container is turned on, and the-t flag tells docker to assign a pseudo tty terminal to create the container. These two parameters are the most basic parameters for creating an interactive container. Without these two parameters, a container is created that runs in the background.
The / bin/bash in the command tells docker to start a bash shell after successfully creating a new container.
The words archlinux, centos and other Linux distributions tell docker what image to use to create the container. Other images can be downloaded from docker, such as the image below. Find the image you need, and the Docker Pull Command column on the right will tell you the corresponding image pull command.
You can pull the image to the local area first and execute the above docker run command. If a local image is detected, docker will no longer go to Docker Hub Registry to check whether there is a corresponding image. If there is no corresponding image locally, check it in Docker Hub Registry. If found, download it locally:
# pull archlinux image sudo docker pull base/archlinux2. Now let's use the first container we just created.
Let's familiarize ourselves with a few common commands before using the container.
# check how many containers there are, how many pauses and how many stops How many are running [bysu@subaoya ~] $sudo docker info# the following is part of the result after running # Containers: 1Running: 0Paused: 0Stopped: 1Images: 1 running # [bysu@subaoya ~] $sudo docker ps # View the running capacity CONTAINER ID IMAGE COMMAND CREATED STATUS d092d144e887 base/archlinux "/ bin/bash" 35 minutes ago Up 12 minutes PORTS NAMES sad_ CONTAINER ID IMAGE COMMAND [bysu @ subaoya ~] $sudo docker ps-a # View Container CONTAINER ID IMAGE COMMAND for all states CREATED STATUS PORTS NAMES2552cacc1928 base/archlinux "/ bin/bash" 33 seconds Exite D26 seconds ecstatic_galileod092d144e887 base/archlinux "/ bin/bash" 35 minutes ago Up 12 minutes sad_rosalind [bysu@subaoya ~] $sudo docker ps-a | grep Up | awk'{print $1}'# View the names of running containers d092d144e887# view the names of all containers sudo docker ps-a-Q # here is the run Result # bfacc5ccb74da56a719eb52a0fc9b2bc3e84# deletes all containers that are not running sudo docker rm $(sudo docker ps-a-Q) # below is the running result # bfacc5ccb74d0fc9b2bc3e84Error response from daemon: You cannot remove a running container a56a719eb52ae8bb3ecbe22bc1b029f203206b0f7144e74992038bb76c56b6ea. Stop the container before attempting removal or force remove# stops a running container sudo docker stop a56a719eb52a# below is the running result # a56a719eb52a
When you create a container in the previous way, you can name the container. If you do not specify a name when you create it, the container name is randomly generated.
Sudo docker run-- name my_first_container-I-t base/archlinux / bin/bash
Generally speaking, if the above container is created successfully, it also goes directly to the container. The first thing I think of is exit (I don't know if there are any other commands to cut out the container, and if you need to use it, use your own search engine). After that, it is possible that the container that has just been cut out has stopped running. This will lead to an exception if you want to enter the container my_first_container again through docker exec-it my_first_container bash or sudo docker attach my_first_container. You need to restart the container by first using the command sudo docker start my_first_container. The container name can be replaced with the container ID in the above command.
View hostname
Hostname
View network interfaces
Ifconfig
Problems that do not exist with the ifconfig command, refer to
Installing other software is the same as in archlinux.
3. Create a guardian container
Guardian containers can run for a long time without interactive sessions and are generally used as carriers for running applications and services. The creation command is as follows:
Sudo docker run-- name my_daemon-d base/archlinux / bin/sh-c "while true;do echo hello docker;sleep 1 done"
In the above command, the-d argument tells docker to run the container in the background.
Since the container created above is placed in the background, we, as the creators of the container, are more or less concerned about whether it is dead or alive.
Sudo docker ps-a
Through the status field, you know that it is still alive. To learn that he is still alive, it is natural to wonder if ta is doing well-- whether he is working properly. You can see how ta is doing by looking at the log.
Sudo docker logs my_daemon
You can use the following commands to view logs in real time.
Sudo docker logs-f my_daemon# real-time view the latest log sudo docker logs-- tail 0-f my_daemon# view the latest log in real time, and add the-t flag to add a timestamp to each log entry to facilitate debugging sudo docker logs-- tail 0-ft my_daemon
Please Ctrl+c to quit. Anyone who has used Linux should know.
[bysu@subaoya ~] $sudo docker attach my_daemon
Hello docker
Hello docker
....
After the code marked red above is executed, the container cannot be exited through Ctrl+c. Helplessly, I can only reconnect the xshell to X. If you know how to turn it off, please let me know (maybe it can't be turned off).
4.Docker log driver
The docker run command is executed with the-- log-driver option. If you specify syslog through this option to redirect all log output of the container to syslog, the docker logs command is also disabled as follows:
Sudo docker run-name my_log_daemon-log-driver= "syslog" >
If you want to disable all logs in the container, the option none is available, which also disables the docker logs command.
5. View the progress in the container
Use sudo docker top my_first_container to view the processes in the container
6.Docker Statistics
You can use the docker stats command to dynamically view the CPU, memory, network speed, and IO of multiple containers, which can quickly monitor a group of containers on a host.
7. Run the process inside the container
Start a new process in addition to the container through the docker exec command. There are two types of processes that can be run within the container: background tasks and interactive tasks.
Run background tasks in the container
Sudo docker exec-d my_first_container touch / etc/createFile
Run interactive commands in the container
Sudo docker exec-t-I my_first_container / bin/bash
If the container is interactive at the time of creation, you can directly attach the sudo docker attach command to the original container with the same effect as the command above.
8. Stop guarded container
Sudo docker stop container name / container ID9. Automatically restart the container
You can use the-- restart flag to let docker restart the container automatically. The restart flag examines the exit code of the container and decides whether to restart the container accordingly. Docker does not restart the container by default.
Always restart the container automatically
Sudo docker run-- restart=always-- name my_daemon-d base/archlinux / bin/sh-c "while true;do echo hello docker;sleep 60 done"
The restart flag is set to always, and Docker automatically restarts the container regardless of the exit code of the container.
If the-- restart flag is set to on-failure, it will restart automatically only if the container exit code is a non-zero value. At the same time, you can also set an optional parameter to mark the number of restarts.
Sudo docker run-- restart=on-failure:5-- name my_daemon-d base/archlinux / bin/sh-c "while true;do echo hello docker;sleep 60 done"
When the container exit code is non-0, Docker will try to restart up to 5 times.
10. Go deep into the container
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.