docker安装与随笔

docker安装与随笔

docker 安装

参照连接

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[root@iz2zegdp0r569zzor0c3quz ~]# tar -xzvf docker-19.03.0.tgz
[root@iz2zegdp0r569zzor0c3quz ~]# cd docker
[root@iz2zegdp0r569zzor0c3quz ~]# mv * /usr/bin/
如果不是默认path目录,那么请用systemctl show-environment/set-environment
[root@iz2zegdp0r569zzor0c3quz ~]# vi .bash_profile
[root@iz2zegdp0r569zzor0c3quz ~]# source .bash_profile
PATH=$PATH:$HOME/bin
[root@iz2zegdp0r569zzor0c3quz ~]# vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/docker
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/local/docker/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

[root@iz2zegdp0r569zzor0c3quz ~]# systemctl daemon-reload
[root@iz2zegdp0r569zzor0c3quz ~]# systemctl start docker

docker-compose 安装

1
2
curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

dockerfile 制作镜像

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@iz2zegdp0r569zzor0c3quz mk]# pwd
/root/mk
[root@iz2zegdp0r569zzor0c3quz mk]# cat Dockerfile
FROM centos

MAINTAINER fengk

ENV DATA_PATH /data
ENV MYSQL_PASSWORD 123456
ENV PATH /usr/local/mysql/bin:$PATH
VOLUME [$DATA_PATH]

COPY my.sh /usr/local/
RUN cd /usr/local && chmod +x my.sh
COPY mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz /usr/local/
RUN yum -y install numactl && yum -y install libaio
RUN groupadd mysql;useradd -r -g mysql -s /bin/false mysql
RUN cd /usr/local && tar -xzvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz && ln -s mysql-5.7.27-linux-glibc2.12-x86_64 mysql && rm -fr mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
EXPOSE 3306
ENTRYPOINT ["/bin/sh","/usr/local/my.sh"]
[root@iz2zegdp0r569zzor0c3quz mk]# cat my.sh
#!/usr/bin/bash
if [ ! -d $DATA_PATH ] ; then mkdir -p $DATA_PATH/data ; fi
if [ ! -d $DATA_PATH/data ] ; then mkdir $DATA_PATH/data ; fi
if [ ! -f $DATA_PATH/mariadb.log ] ; then touch $DATA_PATH/mariadb.log && chown mysql:mysql $DATA_PATH/mariadb.log ; fi
if [ ! -f $DATA_PATH/my.cnf ] ; then cd $DATA_PATH && echo -e "[mysqld]\nuser=mysql\ndatadir=${DATA_PATH}/data\nsocket=${DATA_PATH}/mysql.sock\n[mysqld_safe]\nlog-error=${DATA_PATH}/mariadb.log\npid-file=${DATA_PATH}/mariadb.pid" > my.cnf && chmod 664 my.cnf && chown -R mysql:mysql $DATA_PATH && cd /usr/local/mysql && ./bin/mysqld --defaults-file=$DATA_PATH/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=$DATA_PATH/data && cd /usr/local/mysql && ./bin/mysqld_safe --defaults-file=$DATA_PATH/my.cnf --skip-grant-tables &

var=1
until [ $var -eq 0 ]
do
sleep 1
/usr/local/mysql/bin/mysql -uroot -p123456 --socket=/data/mysql.sock -e "exit"
var=$?
done

cd /usr/local/mysql && ./bin/mysql -uroot --socket=/data/mysql.sock mysql -e "update user set authentication_string=password('$MYSQL_PASSWORD'),password_expired='N'"

cd /usr/local/mysql && ./bin/mysqladmin -u root --socket=$DATA_PATH/mysql.sock shutdown; fi
cd /usr/local/mysql && ./bin/mysqld_safe --defaults-file=$DATA_PATH/my.cnf &
/usr/bin/bash
[root@iz2zegdp0r569zzor0c3quz mk]# ls
Dockerfile my.sh mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
[root@iz2zegdp0r569zzor0c3quz mk]# docker build -t mysql .
[root@iz2zegdp0r569zzor0c3quz mk]# docker run -t -i -v /data:/data -p 3307:3306 --name db mysql
[root@iz2zegdp0r569zzor0c3quz mk]# docker run --link db:db -t -i centos (使用mysql -u*** -p*** -hdb访问上一个容器的mysql)

harbor 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
下载离线安装包
[root@sdw3 ~]# wget https://storage.googleapis.com/harbor-releases/release-1.9.0/harbor-offline-installer-v1.9.1.tgz
[root@sdw3 ~]# tar -xvf harbor-offline-installer-v1.9.1.tgz ; cd harbor
[root@sdw3 harbor]# ./prepare
[root@sdw3 harbor]# vi harbor.yml
hostname: 192.168.106.237
docker-compose需要1.18以上的版本
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/docker/docker-compose
[root@sdw3 harbor]# ./install.sh
剩下使用docker-compose控制
docker-compose start


docker-compose stop