Docker installation
1 Official website The access speed is very slow, Help document
2 domestic Chinese website,Help document
[root@qdlinux ~]# yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine [root@qdlinux ~]# yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 [root@qdlinux ~]# yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo [root@qdlinux ~]# yum-config-manager --enable docker-ce-edge [root@qdlinux ~]# yum-config-manager --enable docker-ce-test [root@qdlinux ~]# yum makecache fast [root@qdlinux ~]# yum install docker-ce
On a production system, you should install a specific version of Docker CE instead of always using the latest version. Lists the available versions. This example uses the sort -r command to sort the results by version number (highest to lowest) and has been truncated.
Note: This yum list command only displays binary packages. If you also need to display the source package, omit. X86? 64 from the package name.
$ yum list docker-ce.x86_64 --showduplicates | sort -r docker-ce.x86_64 17.06.0.el7 docker-ce-stable yum install docker-ce-<VERSION>
systemctl start docker docker run hello-world
Enable alicloud accelerator
[root@qdlinux ~]# vim /etc/docker/daemon.json { "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"] } [root@qdlinux ~]# systemctl daemon-reload [root@qdlinux ~]# systemctl restart docker
[root@qdlinux ~]# docker version Client: Version: 18.09.0-ce-tp4 API version: 1.39 Go version: go1.10.3 Git commit: 33764aa Built: Fri Aug 24 23:20:18 2018 OS/Arch: linux/amd64 Experimental: false Server: Engine: Version: 18.09.0-ce-tp4 API version: 1.39 (minimum version 1.12) Go version: go1.10.3 Git commit: 33764aa Built: OS/Arch: linux/amd64 Experimental: false
[root@qdlinux ~]# docker info Containers: 1 Running: 0 Paused: 0 Stopped: 1 Images: 1 Server Version: 18.09.0-ce-tp4 Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: containerd runc Default Runtime: containerd Init Binary: docker-init containerd version: 6f13ff3ea48a6bc2fb9b47c0acce24cf274dafd9 (expected: 468a545b9edcd5932818eb9de8e72413e616e86e) runc version: 459bfaec1fc6c17d8bfb12d0a0f69e7e7271ed2a (expected: 69663f0bd4b60df09991c08812a60108003fa340) init version: fec3683 Kernel Version: 3.10.0-862.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 1.936GiB Name: qdlinux.com ID: 4HLV:D5DZ:MFZP:QBWO:SKUM:WR32:352C:JZYW:ZAAU:QPGP:3US2:MOY5 Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://y5va7z1k.mirror.aliyuncs.com/ Live Restore Enabled: false
[root@qdlinux ~]# docker --help Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
[root@qdlinux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 2cb0d9787c4d 6 weeks ago 1.85kB
[root@qdlinux ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 2cb0d9787c4d 6 weeks ago 1.85kB
[root@qdlinux ~]# docker images -q 2cb0d9787c4d
[root@qdlinux ~]# docker images -qa 2cb0d9787c4d
[root@qdlinux ~]# docker images --digests REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE hello-world latest sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc 2cb0d9787c4d 6 weeks ago 1.85kB
[root@qdlinux ~]# docker images --digests --no-trunc REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE hello-world latest sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34 6 weeks ago 1.85kB
[root@qdlinux ~]# docker images --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34 6 weeks ago 1.85kB
[root@qdlinux ~]# docker search tomcat NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementati... 1996 [OK] tomee Apache TomEE is an all-Apache Java EE certif... 55 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base... 49 [OK] davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 with... 29 [OK] bitnami/tomcat Bitnami Tomcat Docker Image 21 [OK] consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 16 [OK] cloudesire/tomcat Tomcat server, 6/7/8 15 [OK] tutum/tomcat Base docker image to run a Tomcat applicatio... 11 meirwa/spring-boot-tomcat-mysql-app a sample spring-boot app using tomcat and My... 10 [OK] jeanblanchard/tomcat Minimal Docker image with Apache Tomcat 8 aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 7 [OK] rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl... 3 [OK] maluuba/tomcat7-java8 Tomcat7 with java8. 2 arm64v8/tomcat Apache Tomcat is an open source implementati... 2 amd64/tomcat Apache Tomcat is an open source implementati... 2 jelastic/tomcat An image of the Tomcat Java application serv... 1 99taxis/tomcat7 Tomcat7 1 [OK] camptocamp/tomcat-logback Docker image for tomcat with logback integra... 1 [OK] fabric8/tomcat-8 Fabric8 Tomcat 8 Image 1 [OK] primetoninc/tomcat Apache tomcat 8.5, 8.0, 7.0 1 [OK] oobsri/tomcat8 Testing CI Jobs with different names. 0 swisstopo/service-print-tomcat backend tomcat for service-print "the true, ... 0 cfje/tomcat-resource Tomcat Concourse Resource 0 s390x/tomcat Apache Tomcat is an open source implementati... 0 picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAGER... 0 [OK]
[root@qdlinux ~]# docker search -s 30 tomcat Flag --stars has been deprecated, use --filter=stars=3 instead NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementati... 1996 [OK] tomee Apache TomEE is an all-Apache Java EE certif... 55 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base... 49 [OK]
[root@qdlinux ~]# docker search -s 30 --no-trunc tomcat Flag --stars has been deprecated, use --filter=stars=3 instead NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies 1996 [OK] tomee Apache TomEE is an all-Apache Java EE certified stack where Apache Tomcat is top dog. 55 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 based docker container. 49 [OK]
[root@qdlinux ~]# docker search -s 30 --no-trunc --automated tomcat Flag --stars has been deprecated, use --filter=stars=3 instead Flag --automated has been deprecated, use --filter=is-automated=true instead NAME DESCRIPTION STARS OFFICIAL AUTOMATED dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 based docker container. 49 [OK]
[root@qdlinux ~]# docker pull tomcat Using default tag: latest latest: Pulling from library/tomcat 55cbf04beb70: Pull complete 1607093a898c: Pull complete 9a8ea045c926: Pull complete 1290813abd9d: Pull complete 8a6b982ad6d7: Pull complete abb029e68402: Pull complete d068d0a738e5: Pull complete 42ee47bb0c52: Pull complete ae9c861aed25: Pull complete 60bba9d0dc8d: Pull complete 091c11d70257: Pull complete 869034383fc7: Pull complete Digest: sha256:eab533908d6c7760a84a5edbb4490b648484941dfa708a1c5f4286db8caab825 Status: Downloaded newer image for tomcat:latest
[root@qdlinux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 690cb3b9c7d1 5 days ago 463MB hello-world latest 2cb0d9787c4d 6 weeks ago 1.85kB
[root@qdlinux ~]# docker rmi hello-world Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 9f42fa25318d is using its referenced image 2cb0d9787c4d [root@qdlinux ~]# docker rmi -f hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc Deleted: sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34
[root@qdlinux ~]# docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world 9db2ca6ccae0: Already exists Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc Status: Downloaded newer image for hello-world:latest
[root@qdlinux ~]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx be8881be8156: Pull complete 32d9726baeef: Pull complete 87e5e6f71297: Pull complete Digest: sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424 Status: Downloaded newer image for nginx:latest
[root@qdlinux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 690cb3b9c7d1 5 days ago 463MB nginx latest c82521676580 4 weeks ago 109MB hello-world latest 2cb0d9787c4d 6 weeks ago 1.85kB
[root@qdlinux ~]# docker rmi -f hello-world nginx Untagged: hello-world:latest Untagged: hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc Deleted: sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34 Untagged: nginx:latest Untagged: nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424 Deleted: sha256:c82521676580c4850bb8f0d72e47390a50d60c8ffe44d623ce57be521bca9869 Deleted: sha256:2c1f65d17acf8759019a5eb86cc20fb8f8a7e84d2b541b795c1579c4f202a458 Deleted: sha256:8f222b457ca67d7e68c3a8101d6509ab89d1aad6d399bf5b3c93494bbf876407 Deleted: sha256:cdb3f9544e4c61d45da1ea44f7d92386639a052c620d1550376f22f5b46981af
[root@qdlinux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 690cb3b9c7d1 5 days ago 463MB
//Delete all [root@qdlinux ~]# docker rmi -f $(docker images -qa)
[root@qdlinux ~]# docker pull centos Using default tag: latest latest: Pulling from library/centos 256b176beaff: Pull complete Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf Status: Downloaded newer image for centos:latest [root@qdlinux ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 690cb3b9c7d1 5 days ago 463MB centos latest 5182e96772bf 3 weeks ago 200MB
[root@qdlinux ~]# docker run -it 5182e96772bf [root@5448e5cbace9 /]#
[root@qdlinux ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5448e5cbace9 5182e96772bf "/bin/bash" 5 minutes ago Up 5 minutes optimistic_austin //Container exits completely [root@5448e5cbace9 /]# exit //Container does not stop exiting Ctrl+p+q
[root@qdlinux ~]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5448e5cbace9 5182e96772bf "/bin/bash" 11 minutes ago Exited (0) About a minute ago optimistic_austin
[root@qdlinux ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5448e5cbace9 5182e96772bf "/bin/bash" 12 minutes ago Exited (0) 2 minutes ago optimistic_austin 9f42fa25318d 2cb0d9787c4d "/hello" 3 hours ago Exited (0) 3 hours ago wonderful_mclean
[root@qdlinux ~]# docker ps -n 3 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5448e5cbace9 5182e96772bf "/bin/bash" 13 minutes ago Exited (0) 3 minutes ago optimistic_austin 9f42fa25318d 2cb0d9787c4d "/hello" 3 hours ago Exited (0) 3 hours ago wonderful_mclean
[root@qdlinux ~]# docker ps -lq 5448e5cbace9
[root@qdlinux ~]# docker run -it --name mycentos0828 centos [root@qdlinux ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c566d41cb7fd centos "/bin/bash" 40 seconds ago Up 38 seconds mycentos0828
[root@qdlinux ~]# docker start 5448e5cbace9 [root@qdlinux ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c566d41cb7fd centos "/bin/bash" 8 minutes ago Up 8 minutes mycentos0828 5448e5cbace9 5182e96772bf "/bin/bash" 25 minutes ago Up 15 seconds optimistic_austin
[root@qdlinux ~]# docker restart c566d41cb7fd c566d41cb7fd [root@qdlinux ~]# docker stop c566d41cb7fd c566d41cb7fd [root@qdlinux ~]# docker kill 5448e5cbace9 5448e5cbace9
[root@qdlinux ~]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c566d41cb7fd centos "/bin/bash" 14 minutes ago Exited (137) 2 minutes ago mycentos0828 [root@qdlinux ~]# docker ps -n 2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c566d41cb7fd centos "/bin/bash" 14 minutes ago Exited (137) 2 minutes ago mycentos0828 5448e5cbace9 5182e96772bf "/bin/bash" 30 minutes ago Exited (137) About a minute ago optimistic_austin [root@qdlinux ~]# docker rm 5448e5cbace9 5448e5cbace9 [root@qdlinux ~]# docker ps -n 2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c566d41cb7fd centos "/bin/bash" 15 minutes ago Exited (137) 3 minutes ago mycentos0828 9f42fa25318d 2cb0d9787c4d "/hello" 3 hours ago Exited (0) 3 hours ago wonderful_mclean [root@qdlinux ~]# docker rm -f $(docker ps -qa) [root@qdlinux ~]# docker ps -qa | xargs docker rm
[root@qdlinux ~]# docker run -d centos b307589886194f3da5ae1bcfbbb368c5c3a5ed005341cca52035bc175aab9460 docker run -d centos /bin/sh -c "while true;do echo hello zzyy;sleep 2;done" docker logs container ID docker logs -t container ID docker logs -t -f container ID docker logs -t -f --tail 3 container ID
docker top container ID
Docker inspection container ID
[root@qdlinux ~]# docker attach container ID [root@qdlinux ~]# docker exec -it f702a32dcbc3 ls -l /tmp total 4 -rwx------ 1 root root 836 Aug 4 22:05 ks-script-Lu6hIQ -rw------- 1 root root 0 Aug 4 22:04 yum.log [root@qdlinux ~]# docker cp f702a32dcbc3:/tmp/yum.log /root [root@qdlinux ~]# ll total 8 -rw-------. 1 root root 1735 Aug 4 15:04 anaconda-ks.cfg drwxr-xr-x 2 root root 6 Aug 4 15:57 Desktop drwxr-xr-x 2 root root 6 Aug 4 15:57 Documents drwxr-xr-x 2 root root 6 Aug 4 15:57 Downloads -rw-r--r--. 1 root root 1783 Aug 4 15:07 initial-setup-ks.cfg drwxr-xr-x 2 root root 6 Aug 4 15:57 Music drwxr-xr-x 2 root root 6 Aug 4 15:57 Pictures drwxr-xr-x 2 root root 6 Aug 4 15:57 Public drwxr-xr-x 2 root root 6 Aug 4 15:57 Templates drwxr-xr-x 2 root root 6 Aug 4 15:57 Videos -rw------- 1 root root 0 Aug 5 06:04 yum.log
[root@qdlinux ~]# docker run -it -p 8080:8080 tomcat [root@qdlinux ~]# docker run -it -P tomcat
docker commit -a="zzyy" -m="tomcat without docs" container ID xxx/mytomcat:xxx
docker run -it -v /myDataVolume:/dataVolumeContainer centos docker run -it -v /myDataVolume:/dataVolumeContainer:ro centos
//dockerfile mkdir mydocker cd /mydocker vim Dockerfile # volume test FROM centos VOLUME ["/dataVolumeContainer1","/dataVolumeContainer2"] CMD echo "finish,---------success" CMD /bin/bash docker build -f /mydocker/Dockerfile -t zzyy/centos . docker run -it zzyy/centos /bin/bash //If you make a mistake docker run -it -v /myDataVolume:/dataVolumeContainer --privileged=true centos docker inspect container ID
docker run -it --name dc01 zzyy/centos cd dataVolumeContainer2 touch dc01_add.txt docker run -it --name dc02 --volumes-from dc01 zzyy/centos touch dc02_add.txt docker run -it --name dc03 --volumes-from dc01 zzyy/centos touch dc03_add.txt docker rm -f dc01 //Does not affect other containers, passing shares during the container
FROM scratch ADD centos-7-docker.tar.xz / LABEL org.label-schema.schema-version = "1.0" \ org.label-schema.name="CentOS Base Image" \ org.label-schema.vendor="CentOS" \ org.label-schema.license="GPLv2" \ org.label-schema.build-date="20180531" CMD ["/bin/bash"]
command | explain |
---|---|
FROM | Basic image, which image is the current new image based on |
MAINTAINER | Image maintainer's name and email address |
RUN | Commands to run when building containers |
EXPOSE | Port number exposed by the current container |
WORKDIR | Specify the working directory in which the terminal will log in by default after creating the container |
ENV | Used to set environment variables during image building |
ADD | The files in the host directory are copied into the image, and the ADD command automatically processes the URL and decompresses the tar package |
COPY | Similar to ADD, copy files and directories to the image, and copy files / directories from the image context directory < source path > to the < target path > location in the image of a new layer |
VOLUME | Container data volume for data storage and persistence |
CMD | Specifies the command to run when a container starts. There can be multiple CMD commands in the Dockerfile, but only the last one takes effect. The CMD will be replaced by the parameters after docker run |
ENTRYPOINT | Specify a command to run when the container starts. The purpose of ENTRYPOINT is the same as that of CMD, which specifies the container start program and parameters |
ONBUILD | When building an inherited Dockerfile, run the command, and the onbuild of the parent image will be triggered after the child inherits |
FROM centos MAINTAINER xiaoyu<249935058@qq.com> ENV MYPATH /usr/local WORKDIR $MYPATH RUN yum -y install vim RUM yum -y install net-tools EXPOSE 80 CMD echo $MYPATH CMD echo "success---------ok" CMD ["/bin/bash"]
[root@qdlinux mydocker]# docker build -f /mydocker/Dockerfile -t mycentos:1.3 . [root@qdlinux mydocker]# docker run -it mycentos:1.3 docker history image ID
FROM centos RUN yum -y install curl CMD ["curl","-s","http://ip.cn"] docker build -f /mydocker/Dockerfile2 -t myip . docker run myip FROM centos RUN yum -y install curl ENTRYPOINT ["curl","-s","http://ip.cn"] docker build -f /mydocker/Dockerfile3 -t myip2 . docker run myip2 -i ONBUILD RUN echo "father onbuild-----------"
docker build -t mytomcat9 . [root@qdlinux tomcat9]# docker run -d -p 9090:8080 --name mytomcat9 -v /mydocker/tomcat9/test:/usr/local/apache-tomcat-9.0.11/webapps/test -v /mydocker/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.11/logs --privileged=true mytomcat9
[root@qdlinux mydocker]# docker pull mysql:5.7 [root@qdlinux mydocker]# docker run -p 6666:3306 --name mysql \ > -v /mydocker/mysql/conf:/etc/mysql/conf.d \ > -v /mydocker/mysql/logs:/logs \ > -v /mydocker/mysql/data:/var/lib/mysql \ > -e MYSQL_ROOT_PASSWORD=123456 \ > -d mysql:5.7 c199d9f3a88d99c7f8e8b943b9736d3d145ac35021ca02b6c7bad00d3df102df root@c199d9f3a88d:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> create database db01; Query OK, 1 row affected (0.00 sec) mysql> use db01; Database changed mysql> create table t_book(id int not null primary key,bookName varchar(20)); Query OK, 0 rows affected (0.04 sec) mysql> show tables; +----------------+ | Tables_in_db01 | +----------------+ | t_book | +----------------+ 1 row in set (0.00 sec) mysql> insert into t_book values(1,'java'); Query OK, 1 row affected (0.05 sec) mysql> insert into t_book values(2,'php'); Query OK, 1 row affected (0.02 sec) mysql> select * from t_book; +----+----------+ | id | bookName | +----+----------+ | 1 | java | | 2 | php | +----+----------+ 2 rows in set (0.00 sec)