Go: Docker create LNMP image of CentOS

Source: Internet
Author: User
Tags ssh access docker ps docker run

Transferred from: HTTP://WWW.VCKAI.COM/P/29

1. Installing Docker

This will not be said, will not be able to look at my previous article "Docker Introduction and Installation."

1) Start Docker

# service Docker Start

2. Download the Docker image

Official website Docker Mirror site: https://www.docker.com/, you can view the official website or the third party's Docker image here. Of course, if there is no VPN, the network is relatively slow, you can consider using: https://docker.cn/, this is a domestic mirror site.

1) Download Docker image

# Docker Pull Docker.cn/docker/centos:centos6

Description: The docker pull command is a command that downloads images remotely, similar to Git pull. Docker.cn/docker/centos is the address of the national mirror site CentOS image, if you want to download the official CentOS image, directly using CentOS. : CENTOS6 refers to this image of the tag, I downloaded the CENTOS6, if you want to download the latest version, you can use: Latest or: Centos7.

2) View image

# Docker Images

OK, you can see that the CentOS image has been downloaded.

3. Running the container

Run a container into the shell based on the CentOS image you just downloaded.

1) Run the container and enter the container's shell interface

# docker Run-i-T Docker.cn/docker/centos:centos6/bin/bash

Now that we have entered the shell interface of the container, this is the shell of the CENTOS6 system that we downloaded.

Here is the installation of the LNMP environment in the container.

Here is not detailed said, if not installed LNMP, you can see here: "CENTOS6 under the installation of nginx1.7.9+php5.6.4+mysql5.6.2."

After the installation completes Lnmp, enter exit to exit the mirrored shell interface.

4. Create a new image

First, look at the ID of the container that you just ran (install LNMP) and use that ID to generate a new image.

1) View the container ID that you just ran

# Docker PS-LQ

You can see the ID: fe77b1628688, below we submit the next container to generate a new image.

2) Submit Create new Image

# Docker Commit fe77b VCKAI/DEV:V1

fe77b1628688 here generally only need to use the first few digits on the line, as long as not repeat can be recognized, you can not enter all, VCKAI/DEV:V1 is the new image name I generated, if you enter the existing image name, it will overwrite the original image.

Here you can see that a new image has been generated, with the ID: 8717b405408e3df2a12b503e327226d35d6ce118ebc66178ca2bfe440bcb8f04.

3) View all images

# Docker Images

As you can see, the image we generated just now is here.

5. Boot image

# Docker run-d-P 80:80-v/web:/www vckai/dev:v1/sbin/init

-D is run in daemon mode.

The-P 80:80 is a port that maps a local 80 port to a container of 80 and can now be accessed locally using http://localhost.

-v/web:/www is the directory where the local/web directory is mounted to the container's/www (the container-configured web directory).

VCKAI/DEV:V1 is the name of the image to run.

/sbin/init is the system initialization operation after the container is run, mainly used to start the Nginx,php-fpm,mysql service.

1) View the images in the Docker runtime

# docker PS

2) Stop/restart/kill/start container (optional)

# docker Stop/restart/kill/start <ID/Name>

More container operations commands can be seen in this article: Docker Learning notes.

This time you can already use http://localhost to visit your website, gee, strange, incredibly can't access! Suddenly remember not to configure the boot boot in the container, even when the/sbin/init initialization did not start up the nginx+php+mysql.

Now it is only possible to stop the container, then enter the Vckai/dev:v1 container, add Nginx, PHP, and MySQL startup runs in the/etc/rc.local file, and then overwrite the vckai/dev:v1 in the Docker commit submission.

In addition, if already in the running container, how to enter the view? Two ways, one SSH, the other using Nsenter. However, SSH access is not recommended: why you do not need to run sshd in a Docker container.

1) Install Nsenter

# Docker run--rm-v/usr/local/bin:/target jpetazzo/nsenter

2) Enter the container shell in operation

# Docker-enter 65615A

65615A is the container ID we just saw with Docker PS.

3) Start the nginx+php of the container

#/data/apps/nginx/sbin/nginx#/DATA/APPS/PHP/SBIN/PHP-FPM

OK, now open the site is working properly!

Resources:

Docker Tutorial Chinese version: Https://code.csdn.net/u010702509/docker

Nsenter Github:https://github.com/jpetazzo/nsenter

Docker Command Learning Note: Http://blog.csdn.net/we_shell/article/details/38368137?utm_source=tuicool

FAQ:

Docker run-d-P 80:80-v/web:/www vckai/dev:v1/sbin/init
How can I cancel this order?

A: View the container's ID through Docker PS and stop the container via Docker stop < container id>

Go: Docker create LNMP image of CentOS

Related Article

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.