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

You don't know the container who plays big data? Installation of Docker and MySQL for getting started with Docker

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

Share

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

1. Brief introduction

Docker is an open source application container engine; it is a lightweight container technology

Docker supports compiling the software into an image, and then various software is configured in the image to publish the image, which can be directly used by other users.

The running image is called the container, and the container startup is very fast.

two。 Core concept

Docker host (Host): a machine with Docker programs installed (Docker is installed directly on top of the operating system)

Docker client (Client): connect to the docker host for operation

Docker repository (Registry): used to hold various packaged software images

Docker image (Images): an image packaged by software; placed in the docker repository

Docker container (Container): the instance after the image is started is called a container; the container is one or a group of applications that run independently

3. Installation environment VM ware Workstation10CentOS-7-x86_64-DVD-1804.isouname-r3.10.0-862.el7.x86_64

To check the kernel version, it must be 3.10 or above. View command: uname-r

4. Install docker on the linux virtual machine

Steps:

1. Check the kernel version, which must be 3.10 or above

Uname-r

2. Install docker

Yum install docker

3. Enter y to confirm the installation

Dependency Updated: audit.x86_64 0vl 2.8.1-3.el7_5.1 audit-libs.x86_64 0vir 2.8.1-3.el7_5.1 Complete! (sign of success)

4. Start docker

[root@hadoop000] # systemctl start docker [root@hadoop000] # docker-vDocker version 1.13.1, build 8633870 pick 1.13.1

5. Boot and start docker

[root@hadoop000] # systemctl enable dockerCreated symlink from / etc/systemd/system/multi-user.target.wants/docker.service to / usr/lib/systemd/system/docker.service.

6. Stop docker

[root@hadoop000] # systemctl stop docker5. Common command

Mirror operation

Operation command instructions to retrieve the docker search keyword eg:docker search redis We often go to the docker hub to retrieve the details of the image, such as the TAG of the image to pull the docker pull image name: tag:tag is optional, tag indicates the label, mostly the version of the software. The default is latest list docker images to view all local images delete docker rmi image-id to delete the specified local image

Of course, you can also find it on the official website: https://hub.docker.com/

Container operation

Software image (QQ installer)-- running image-- produces a container (running software, running QQ)

Steps:

1. Search for images

[root@localhost ~] # docker search tomcat

2. Pull the image

[root@localhost ~] # docker pull tomcat

3. Start the container according to the image

Docker run-name mytomcat-d tomcat:latest

4. View the containers in operation

Docker ps

5. Stop the container in operation

Id of the docker stop container

6. Check all the containers

Docker ps-a

7. Start the container

Docker start Container id

8. Delete a container

Docker rm Container id

9. Start a tomcat with port mapping

[root@localhost] # docker run-d-p 8888purl 8080 tomcat

-d: running in the background

-p: map the port of the host to a port of the container: the port inside the container

10. To demonstrate, simply turn off linux's firewall

Service firewalld status #; check the firewall status service firewalld stop #: turn off the firewall systemctl disable firewalld.service # disable firewall boot

11. View the container log

Docker logs container-name/container-id

For more commands, see

Https://docs.docker.com/engine/reference/commandline/docker/

You can refer to the mirror documentation

6. Use docker to install mysql > docker pull mysqldocker pull mysql Using default tag: latestTrying to pull repository docker.io/library/mysql. Latest: Pulling from docker.io/library/mysqla5a6f2f73cd8: Pull complete 936836019e67: Pull complete 283fa4c95fb4: Pull complete 1f212fb371f9: Pull complete e2ae0d063e89: Pull complete 5ed0ae805b65: Pull complete 0283dc49ef4e: Pull complete a7e1170b4fdb: Pull complete 88918a9e4742: Pull complete 241282fa67c2: Pull complete b0fecf619210: Pull complete bebf9f901dcc: Pull complete Digest: sha256:b7f7479f0a2e7a3f4ce008329572f3497075dc000d8b89bac3134b0fb0288de8Status: Downloaded newer image for docker.io/mysql:latest [root@hadoop000 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/mysql latest F991c20cb508 10 days ago 486 MB launches [root@hadoop000 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/mysql latest f991c20cb508 10 days ago 486 MB [root@hadoop000 ~] # docker run-- name mysql01-d mysql756620c8e5832f4f7ef3e82117c31760d18ec169d45b8d48c0a10ff2536dcc4a [root@hadoop000 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES756620c8e583 mysql "docker-entrypoint..." 9 seconds ago Exited (1) 7 seconds ago mysql01 [root@hadoop000 ~] # docker logs 756620c8e583error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

You can see that the startup method above is wrong, prompting us to bring a specific password.

[root@hadoop000 ~] # docker run-p 3306 MYSQL_ROOT_PASSWORD=123456 3306-- name mysql02-e MYSQL_ROOT_PASSWORD=123456-d mysqleae86796e132027df994e5f29775eb04c6a1039a92905c247f1d149714fedc06-name: name the newly created container, here pwc-mysql-e: configuration information, configure the login password of the root user of mysql here-p: Port mapping, here map host port 3306 to container pwc-mysql port-d: output the complete ID of the container after successfully starting the container, such as figure 73f8811f669ee above. Check whether [root@hadoop000 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESeae86796e132 mysql "docker-entrypoint..." 8 minutes ago Up 8 minutes 0.0.0.0 docker-entrypoint... 3306-> 3306/tcp has been started successfully 33060/tcp mysql02 log in to MySQLdocker exec-it mysql04 / bin/bashroot@e34aba02c0c3:/# mysql-uroot-p123456 mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 80Server version: 8.0.13 MySQL Community Server-GPLCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql >

Other advanced operations

Docker run-- name mysql03-v / conf/mysql:/etc/mysql/conf.d-e MYSQL_ROOT_PASSWORD=my-secret-pw-d mysql:tag

Mount the / conf/mysql folder of the host to the / etc/mysql/conf.d folder of the mysqldocker container

To change the mysql configuration file, just put the mysql configuration file in a custom folder (/ conf/mysql)

Docker run-name some-mysql-e MYSQL_ROOT_PASSWORD=my-secret-pw-d mysql:tag-character-set-server=utf8mb4-collation-server=utf8mb4_unicode_ci

Specify some configuration parameters for mysql

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