Kubernetes-Docker基础
2021-03-12 01:32
标签:ext4 doc git ted format uid 说明 tps x86 docker-ce.x86_64 # 社区版 注释/etc/fstab 在docker服务器上使用容器IP可以访问到容器服务器,对于生产网络不可见 To be continue! Kubernetes-Docker基础 标签:ext4 doc git ted format uid 说明 tps x86 原文地址:https://www.cnblogs.com/bigdad/p/14506872.html1. Docker版本
docker-ee # 企业版
docker镜像站:https://hub.docker.com/
Kubernetes:https://kubernetes.io/zh/
阿里云镜像站:https://developer.aliyun.com/special/mirrors/notice
#:docker version
Client:
Version: 19.03.8
API version: 1.40
Go version: go1.13.8
Git commit: afacb8b7f0
Built: Fri Dec 18 12:15:19 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.13.8
Git commit: afacb8b7f0
Built: Fri Dec 4 23:02:49 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.3-0ubuntu2.2
GitCommit:
runc:
Version: spec: 1.0.1-dev
GitCommit:
docker-init:
Version: 0.18.0
GitCommit:
2. 环境准备
#: hostnamectl set-hostname worker
#: sysctl -a | grep forward
***
net.ipv4.ip_forward = 1
***
#: vim /etc/sysconfig/selinux 或者 setenforce 0
SELINUX=permissive
swapoff /swap.img
root@k8s:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use ‘blkid‘ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
systemctl stop firewalld
#: wget https://download.docker.com/linux/centos/docker-ce.repo -O /etc/yum.repo.d
#: yum repolist
#: yum -y install docker-ce docker-ce-cli containerd.io
#: systemctl start docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json
3. Docker常用操作
docker search nginx
docker pull nginx:latest
root@node1:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 7 weeks ago 449MB
busybox latest b97242f89c8a 7 weeks ago 1.23MB
nginx latest f6d0b4767a6c 8 weeks ago 133MB
metallb/speaker main 252ca41551e9 2 months ago 84.3MB
metallb/controller main 3a44dd1ab374 2 months ago 75.3MB
centos latest 300e315adb2f 3 months ago 209MB
docker run -dit --name=nginx web1
docker ps -a
docker ps -a | grep Exited | awk ‘{print $1}‘
docker ps -a | grep Exited | awk ‘{print $1} > /tmp/stop-c
while read c; do docker rm $c; done
docker save docker.io/nginx > nginx.tar
docker load -i nginx.tar
查看详细命令:docker history --no-trunc docker.io/nginx
root@node1:~# docker history nginx
IMAGE CREATED CREATED BY SIZE COMMENT
f6d0b4767a6c 8 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
4. 容器常规操作
root@node1:~# docker run -dit --restart=always --name=c1 centos:latest
314ffbcdfa193f38d73dffa026dd816a917dad0d3367916ea5a71fba593d6beb
root@node1:~#
# 启停容器
docker stop/start c1
# 删除容器
docker rm c1 -f
# 访问容器
attach: 容器中要有bash/sh
docker attach c1
# 容器中运行命令
docker exec c1 /bin/bash -c "cat /etc/redhat-release"
docker exec c1 /bin/bash -c "yum install net-tools -y"
docker commit c1 my-centos
docker run -dit --restart=always -e MYSQL_ROOT_PASSWORD=redhat --name=my-db mysql:5.7
Mysql数据库使用前参考使用说明:https://hub.docker.com/_/mysql
* 查看容器中环境变量
root@node1:~# docker run -dit --restart=always -e MYSQL_ROOT_PASSWORD=redhat --name=my-db mysql:5.7
0d96ee5757c8323732daf153d0d7b2d7d1d1b0c0e18d22ccab9c23c40600aead
root@node1:~# docker exec -it my-db bash
root@0d96ee5757c8:/# env
MYSQL_MAJOR=5.7
HOSTNAME=0d96ee5757c8
PWD=/
MYSQL_ROOT_PASSWORD=redhat
HOME=/root
MYSQL_VERSION=5.7.33-1debian10
GOSU_VERSION=1.12
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@0d96ee5757c8:/#
* 查看容器详细信息
docker inspect my-db
docker run -dit --restart=always --name=my-db2 -e MYSQL_ROOT_PASSWORD=redhat -v /mysql:/var/lib/mysql mysql:5.7
5. 容器网络
root@node1:~# docker network list
NETWORK ID NAME DRIVER SCOPE
a390d4dd97e4 bridge bridge local
7ecb1cba6445 host host local
5c842fd3da29 none null local
root@node1:~# dokcer network inspect a390d4dd97e4
man 1 docker-network-create
docker network create --driver=bridge --subnet=10.0.0.0/24 network1
* 指定network1创建容器
docker run -dit --restart=always --name=c2 --network=network1 centos:7
docker run -dit --restart=always --name=web1 -p 80:80 --network=network1 nginx
docker pull wordpress
docker pull mysql:5.7
#: docker run -dit --restart=always --name=mysql -e MYSQL_ROOT_PASSWORD=redhat -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -e MYSQL_DATABASE=wordpress mysql:5.7
#: docker run -dit --restart=always --name=wordpress -e WORDPRESS_DB_HOST=x.x.x.x -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -e WORDPRESS_DB_NAME=wordpress -p 80:80 wordpress
* 或者
#: docker run -dit --restart=always --name=mysql -e MYSQL_ROOT_PASSWORD=redhat -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -e MYSQL_DATABASE=wordpress -v /wp-mysql:/var/lib/mysql mysql:5.7
#: docker run -dit --restart=always --name=wordpress --link mysql:db -e WORDPRESS_DB_HOST=db -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -e WORDPRESS_DB_NAME=wordpress -v /wpdata:/var/www/html -p 80:80 wordpress
上一篇:PHP之简单的文件上传
下一篇:js正则表达式
文章标题:Kubernetes-Docker基础
文章链接:http://soscw.com/index.php/essay/63464.html