Centos7 docker container (2) Running and removing in-container applications

Source: Internet
Author: User
Tags nginx server docker ps
Install, run, and remove docker applications to run and save docker containers

1. Run and save the nginx Server Based on the Ubuntu docker container. Install the nginx daemon to the Ubuntu startup container:

# Docker run Ubuntu bash-c "apt-get-y install nginx"

650) This. width = 650; "Title =" Capture. PNG "alt =" wKioL1gyiuiRWi-xAABXodVK2Y8290.png "src =" http://s5.51cto.com/wyfs02/M00/8A/7C/wKioL1gyiuiRWi-xAABXodVK2Y8290.png "/>

2. After installing the nginx package, run docker PS-L to get the ID or name of the running container. Run the following command:

# Docker PS-l

650) This. width = 650; "Title =" Capture 1.png" alt = "wKiom1gyjQfySg-MAAASyuIJKZM035.png" src = "http://s5.51cto.com/wyfs02/M00/8A/80/wKiom1gyjQfySg-MAAASyuIJKZM035.png"/>

Run the following command to get the changes

# Docker commit 5976e4ae287c Ubuntu-nginx

5976e4ae287c ------ container ID and Ubuntu nginx ------ container name

Run the docker image command to view the list of all saved image files.

# Docker Images

650) This. width = 650; "Title =" Capture 3.png" alt = "wkiol1gyjzzs4ed5aaazkatadqo366.png" src = "http://s1.51cto.com/wyfs02/M00/8A/7C/wKioL1gyjzzS4eD5AAAzkaTadQo366.png"/>

Because the installation process in the container is completed quickly, a container that is not running may be stopped ). In this case, the docker ps command does not display any content because no container is running.
Run the docker PS-A | head-3 command to list the container creation and exit statuses.

3. Run the docker container session docker run-It Ubuntu bash command to install the container software, for example, Apt-Get install nginx command. When running, run and exit the container by pressing Ctrl-P or Ctrl + Q to end the nginx installation process.

# Docker run-It Ubuntu bash
# Apt-Get install nginx

650) This. width = 650; "Title =" Capture 4.png" alt = "wkiol1gykfvwyg56aabweatq9b4043.png" src = "http://s3.51cto.com/wyfs02/M01/8A/7C/wKioL1gykFvwyG56AABWeatq9b4043.png"/>

Then, run the docker ps command to view the container changes and IDs. After that, use docker to re-enter the container console, and then type exit to stop the container.

# Docker PS
# Docker attach 3378689f2069
# Exit

650) This. width = 650; "Title =" Capture 5.png" alt = "wkiom1gyltagxvu7aaabh_n5cfq161.png" src = "http://s3.51cto.com/wyfs02/M01/8A/80/wKiom1gylTagXvu7AAAbH_n5CFQ161.png"/>

4. The nginx service has been installed. Run the following command to generate a new container and back up the binary data of nginx. The installation is successful:

# Docker run Ubuntu-nginx whereis nginx

650) This. width = 650; "Title =" Capture 6.png" alt = "wkiol1gylecrnz14aaanm1yrm8y111.png" src = "http://s4.51cto.com/wyfs02/M01/8A/7D/wKioL1gyleCRNz14AAANM1yrM8Y111.png"/>

5. To delete a container, run the RM command. Because the container ID or name is required, run the docker PS-a command to obtain the following information:

# Docker PS-
# Sudo docker RM 36488523933a

650) This. width = 650; "Title =" Capture 7.png" alt = "wkiom1gyllpw7mftaabsizdvgre404.png" src = "http://s1.51cto.com/wyfs02/M02/8A/81/wKiom1gyllPw7MFTAABSizdvgrE404.png"/>

How to run nginx

6. Run and access network services, such as nginx Web server. In dockez, use the Ubuntu-nginx image to create the nginx daemon process.
First, create a new container, map the host container port, and run the following command to enter the container shell:

# Docker run-it-P 81: 80 Ubuntu-nginx/bin/bash
# Nginx &

Here,-POption to list the host port to container port. The host port can be arbitrary, and the container port must be a completely internal process listening port. Once you connect to the container session, start the daemon in the background and exit the container console by pressing Ctrl-P and CTRL + q.

650) This. width = 650; "Title =" Capture 8.png" alt = "wkiom1gyl8vb1flbaaayspw9ira151.png" src = "http://s2.51cto.com/wyfs02/M01/8A/81/wKiom1gyl8vB1FlbAAAYSpw9IrA151.png"/>

7. Run docker PS to check the running container status. Run the following command to view the network socket of the Host:

# Docker PS
Or
# Netstat-tlpn

650) This. width = 650; "Title =" Capture 9.png" alt = "wkiol1gymswsvxfiaaa14ivul14529.png" src = "http://s4.51cto.com/wyfs02/M02/8A/7D/wKioL1gymSWSvXFIAAA14iVul14529.png"/>

8. Use the nginx Container service access page to open the IP address of the browser from a remote location or LAN, and use the HTTP protocol on the machine.

650) This. width = 650; "Title =" Capture 10.png" alt = "wkiom1gymcuyzkx1aaev_oyt2wu480.png" src = "http://s2.51cto.com/wyfs02/M02/8A/81/wKiom1gymcuyZkX1AAEv_OYt2wU480.png"/>

9. Run the following command to stop a container: container, identifier, or name

# Docker PS
# Docker stop fervent_mccarthy
# Docker PS

650) This. width = 650; "Title =" Capture 11.png" alt = "wkiol1gyou7yfiiraaclhgna2qw457.png" src = "http://s1.51cto.com/wyfs02/M00/8A/7E/wKioL1gyoU7yfiiRAAClhgna2Qw457.png"/>

10. Exit container running

# Docker attach fervent_mccarthy
# Exit:

This article is from the blog "ruihang departure-next-generation enterprise application!

Centos7 docker container (2) Running and removing in-container applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.