1.在线安装curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun,下面我们就来说一说关于docker安装使用教程?我们一起去了解并探讨一下这个问题吧!

docker安装使用教程(Docker安装教程)

docker安装使用教程

安装Docker

1.在线安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

在线安装方式二

curl -sSL https://get.daocloud.io/docker | sh

3.查看docker

yum list docker-ce --showduplicates | sort -r

Installed Packages docker-ce.x86_64 3:20.10.8-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.8-3.el8 @docker-ce-stable docker-ce.x86_64 3:20.10.7-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.6-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.4-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.3-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.2-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.1-3.el8 docker-ce-stable docker-ce.x86_64 3:20.10.0-3.el8 docker-ce-stable docker-ce.x86_64 3:19.03.15-3.el8 docker-ce-stable docker-ce.x86_64 3:19.03.14-3.el8 docker-ce-stable docker-ce.x86_64 3:19.03.13-3.el8 docker-ce-stable

4.查看Docker版本

docker version

Client: Docker Engine - Community Version: 20.10.8 API version: 1.41 Go version: go1.16.6 Git commit: 3967b7d Built: Fri Jul 30 19:53:39 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.8 API version: 1.41 (minimum version 1.12) Go version: go1.16.6 Git commit: 75249d8 Built: Fri Jul 30 19:52:00 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.9 GitCommit: e25210fe30a0a703442421b0f60afac609f950a3 runc: Version: 1.0.1 GitCommit: v1.0.1-0-g4144b63 docker-init: Version: 0.19.0 GitCommit: de40ad0

5.启动Docker

systemctl start docker

6.测试Docker是否启动成功

(1).拉取HelloWorld的镜像

docker pull hello-world

Using default tag: latest latest: Pulling from library/hello-world Digest: sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1 Status: Image is up to date for hello-world:latest docker.io/library/hello-world:latest

(2).运行hello-world镜像

docker run hello-world

看到下面的图就证明安装成功了

Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/

Docker 安装各种开发必备内容1.Docker 安装 Redis
  1. 查看 Redis 的版本

docker search redis

2.取最新版的 Redis 镜像

docker pull redis:latest

3.查看本地镜像

docker images

4.运行容器(这是只能本地访问,但是我们需要进行外网访问)

docker run -itd --name redis-test -p 6379:6379 redis

-p 6379:6379:映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务。

5.通过 redis-cli 连接测试使用 redis 服务。

docker exec -it redis-test /bin/bash

6.查看 Redis是否启动成功

ps aux | grep redis-server

出现如下,则为成功

systemd 27456 0.4 0.6 52976 12932 ? Ssl 17:29 0:00 redis-server *:6379 root 27495 0.0 0.0 12112 1088 pts/1 S 17:30 0:00 grep --color=auto redis-server

上面的方法只能本地访问,我们需要的是外网访问redis

4.创建conf 和 data 文件夹

mkdir /usr/local/docker/conf

/usr/local/docker/data

然后再conf下创建redis.conf 的配置文件

放入如下内容,密码可不用配置

#bind 127.0.0.1 //允许远程连接 protected-mode no appendonly yes //持久化 requirepass 123456 //密码

  1. 创建redis容器并启动

docker run --privileged=true --name redis-server -p 6379:6379 -v /usr/local/docker/data:/data -v /usr/local/docker/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf

6.查看Redis是否启动

docker ps

就可以看到redis了,如果状态是UP,那么就可以确定是安装成功了,启动完成之后,把云服务器的6379端口出入打开,就可以看到了。

这时候我们就可以去使用外部工具进行连接了。

2.Docker 安装 Mysql

1.拉取镜像

docker pull mysql

2.在opt下创建文件夹

cd /opt/

mkdir mysql_docker

cd mysql_docker/

echo $PWD

3.启动mysql容器,在var/lib/docker/containers/下查看容器

docker run --name mysqlserver -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 mysql:latest

cd /var/lib/docker/containers/

4.查看mysql进程

docker ps -a

5.进入mysql容器,并登陆mysql

docker exec -it mysqlserver bash

mysql -uroot -p

123456

6.开启远程访问权限

use mysql;

select host,user from user;

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

flush privileges;

然后去连接一下数据库测试就可以了

7.关闭docker中mysql容器

docker stop mysqlserver

8.关闭docker

systemctl stop docker

,