龙空技术网

做一个自己的Docker Image

代号香蕉 376

前言:

现时我们对“dockercentosimage”大体比较珍视,各位老铁们都想要学习一些“dockercentosimage”的相关资讯。那么小编同时在网络上搜集了一些对于“dockercentosimage””的相关资讯,希望我们能喜欢,各位老铁们一起来学习一下吧!

1安装docker基本环境

1首先创建Docker的yum仓库

[root@jian ~]# vi /etc/yum.repos.d/docker.repo

[dockerrepo]

name=Docker Repository

baseurl=

enabled=1

gpgcheck=1

gpgkey=

2启动docker服务

[root@jian ~]# systemctl start docker

3下载一个docker镜像

这里选择最基本的centos镜像即可

[root@jian ~]# docker search centos

NAME DESCRIPTION STARS OFFICIAL AUTOMATED

centos The

official build of

CentOS. 4716 [OK]

[root@jian ~]# 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@jian ~]# docker images

REPOSITORY TAG IMAGE

ID CREATED SIZE

centos latest 5182e96772bf 6

weeks ago 200MB

4启动镜像

启动后会将基于该镜像的容器id作为回显打印在屏幕上

[root@jian ~]# docker run -itd centos

f703c011abe3f17df0b805009dedd66de663bce6d8c6a84913bf231503951f59

5进入容器

[root@jian ~]# docker exec -it

f703c011abe3f17df0b805009dedd66de663bce6d8c6a84913bf231503951f59 bash

2安装辅助工具

因为下载的镜像中是一个精简版,需要安装一些工具方便我们使用

1安装网络工具包这样我们就可以查看当前容器的ip地址

[root@f703c011abe3 ~]# yum install net-tools –y

[root@f703c011abe3 ~]# ifconfig

eth0:

flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet

172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0

2安装ssh工具包

[root@f703c011abe3 ~]# yum install passwd openssl openssh-server

openssh-client –y

3安装mariadb

[root@jian ~]# scp -r mariadb-10.3.9-linux-x86_64.tar.gz

172.17.0.3:/

[root@f703c011abe3 mariadb-10.3.9]# yum install libaio

[root@f703c011abe3 ~]#tar zxvf mariadb-10.3.9-linux-x86_64.tar.gz

[root@f703c011abe3 /]# useradd mysql

[root@f703c011abe3 /]# chown mysql.mysql /mariadb-10.3.9/ -R

[root@f703c011abe3 /]# mkdir /jian/datadg -p

[root@f703c011abe3 /]# mkdir /jian/datadg/log -p

[root@f703c011abe3 /]# mkdir

/jian/binlog

[root@f703c011abe3 /]# mkdir /jian/tmp

[root@f703c011abe3 /]# chown mysql.mysql /jian -R

[root@f703c011abe3 /]# vi /etc/my.cnf

[root@f703c011abe3 /]# chown mysql.mysql /etc/my.cnf

[mysql@f703c011abe3 ~]$ cd /mariadb-10.3.9/

[mysql@f703c011abe3 mariadb-10.3.9]$ ./scripts/mysql_install_db

3将已安装过mariadb的容器进行打包

1将当前的容器另存为一个新的镜像

[root@jian ~]# docker ps

CONTAINER

ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f703c011abe3 centos "/bin/bash" 31

minutes ago Up 31

minutes angry_hermann

[root@jian ~]# docker commit f703c011abe3 centos-mariadb

2将镜像打包

[root@jian ~]# docker save -o

/centos-mariadb.tar centos-mariadb

3使用自己的镜像

[root@localhost /]# docker load -i centos-mariadb.tar

1d31b5806ba4: Loading layer

[==================================================>] 208.3MB/208.3MB

749314e7fdf1: Loading layer

[==================================================>] 2.592GB/2.592GB

Loaded image: centos-mariadb:latest

[root@localhost /]# docker images;

REPOSITORY TAG IMAGE

ID CREATED SIZE

centos-mariadb latest 26de8ce07e68 21

hours ago 2.78GB

[root@localhost /]# docker run -itd centos-mariadb

7c24bc7101440f6aff9718eef32e9f74305d1965042540245aaf45e1f55aba5e

[root@localhost /]# docker exec -it

7c24bc7101440f6aff9718eef32e9f74305d1965042540245aaf45e1f55aba5e bash

[root@7c24bc710144 /]# su - mysql

Last login: Mon Sep 17 15:46:35 UTC 2018

[mysql@7c24bc710144 ~]$ mysqld_safe &

[1] 44

[mysql@7c24bc710144 ~]$ 180918 14:36:12 mysqld_safe Logging to

'/jian/datadg/log/alert_Jian.log'.

180918 14:36:12 mysqld_safe Starting mysqld daemon with

databases from /jian/datadg/db

[mysql@7c24bc710144 ~]$ mysql -uroot

Welcome to the MariaDB monitor. Commands end with ;

or \g.

Your MariaDB connection id is 6

Server version: 10.3.9-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and

others.

Type 'help;' or '\h' for help. Type '\c' to clear the current

input statement.

14:36:17 (root@localhost) [(none)]> quit

Bye

如果对以上的任何一步有疑问,大家可以留言

标签: #dockercentosimage