Docker

学习docker pull、docker run、docker exec、docker logs的基本使用

基本题目

1
2
3
4
5
6
7
8
9
10
11
docker search mysql
docker pull mysql:latest //拉取mysql
docker images //查看所拥有的映像
docker run -itd --name mysql-1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD = 123456 mysql
//这里的--name mysql-1就是在命名创建出来的容器为mysql-1 3306表示为端口 MYSQL_ROOTPASSWORD表示这里的mysql密码

docker ps //找到相应镜像的container ID
docker exec -it d37c7d7397d4 /bin/bash //进入到docker内的数据库地址
mysql -uroot -p
123456//输入密码
create schema schema1; //创建schema对象 名为schema1

Docker Compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ubuntu 构建
version: '3'
services:
ubuntu1:
container_name: ubuntu-1
build:
context: ./
dockerfile: Dockerfile
restart: on-failure
tty: true
network_mode: host


ubuntu2:
container_name: ubuntu-2
build:
context: ./
dockerfile: Dockerfile
restart: on-failure
tty: true
networks:
other-network:
aliases:
- alias2
networks:
other-network:
# Use a custom driver which takes special options
driver: bridge
1
2
FROM ubuntu
WORKDIR /here

ubuntu PING 的设定

1
2
apt-get update
apt install iputils-ping