Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Cloud Computing Learning Roadmap material Courseware: Docker Container Application scenario Analysis

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Docker container is an open source application container engine, which can automatically perform repetitive tasks, such as building and configuring the development environment. Users can easily create and use containers, as well as version management, replication, sharing, and modification. There are many beginners in cloud computing who are not clear about the use of Docker containers and application scenarios. Next, we will briefly share the cloud computing learning roadmap material courseware: Docker container application scenario analysis.

Docker is an open source application container engine developed in Go language, which is implemented based on LXC (Linux Container) kernel virtualization technology, and provides a series of stronger functions, such as mirroring, Dockerfile, etc.

The idea of Docker is to package the applications and dependencies into a portable container, which can be released to the Docker engine of any Linux distribution, and the sandbox mechanism is used to run the program. The programs are isolated from each other.

Docker adopts Cpact S architecture. As a server, Dcoker daemon accepts requests from the client and processes these requests, such as creating and running containers. The client provides users with a series of instructions to interact with Docker Daemon.

Docker is developed and implemented by Go language developed by Google. Based on cgroup, namespace and AUFS UnionFS technology of Linux kernel, the process is encapsulated and isolated, which belongs to the virtualization technology at the operating system level. Currently, the application scenarios of Docker containers include the following:

Docker deploys Mongodb environment

1. Obtain Mongodb image remotely

Docker pull mongo

2. Create a docker container

Docker run-p 27017 mongo 27017-v / data/db-- name docker_mongodb-d mongo

In the above command, several command parameters are explained in detail as follows:

-p specify the port mapping of the container (special note: the front is the local port, and the back is the container port. Add the-p parameter to actively leak the container internal port, mapping the server port 27017 to the container port 27017, so that our service can be accessed through the server port 27017 in the public network. The default port of Mongodb is 27017.

-v is the mount directory of the setting container. Here, the directory in the local machine is mounted to / data/db in the container as the storage directory of Mongodb.

-- name is the name that sets the container

-d sets the container to run as a daemon

3. Test the Mongodb in the connection container

Complete process of Docker deployment Node project (DockerFile practice)

1. Use Koa2 to initialize a Node project, connect Mogodb database through Mongose middleware, and implement a basic interface Mogodb to insert data.

2. Create a .dockerkeeper file in the root directory of the project, and filter the files that do not need to be packaged into Docker Image:

/ usr/src/nodejs/dockerstudy/.dockerignore

.git

Node_modules

3. Create a Dockerfile file in the root directory of the project, and when you deploy the Node project, there will be a Dockerfile file configuration.

/ usr/src/nodejs/hello-docker/Dockerfile

FROM node:10.0

Create a directory in the container

RUN mkdir-p / usr/src/nodejs/

Navigate to the working directory of the container

WORKDIR / usr/src/nodejs/

RUN/COPY is layered and package.json is in advance. As long as there is no modification, the package will not be reinstalled.

COPY package.json / usr/src/app/package.json

RUN cd / usr/src/app/

RUN npm i

Copy all the files in the current directory to the / usr/src/nodejs/ directory of Image

COPY. / usr/src/nodejs/

EXPOSE 3000

CMD npm start

4. The code section is over for the time being, and the Dockerfile will be submitted to github or gitlab, etc.

5. First check out the code and clone the project to the specified directory.

6. Enter the directory construction.

7. Create a container and run it by mirroring dockerstudy.

8. Enter the container.

9. Log check to check the running log.

Elegant deployment mode DockerCompose

Compose is an official open source project of Docker, which can manage multiple Docker containers to form an application, such as Web service. In addition to the service itself, there are a series of related services such as database, Redis, Nginx and so on that need to be installed. With Compose support, we only need to define a configuration file (docker-compose.yml) in YAML format to write multiple container configurations and invocation relationships needed for a project, and we can start or close these containers at the same time with a simple command. Compose positioning is an application that defines and runs multiple Docker containers.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report