Loading

docker 学习记录

一、参考资源

Docker退出容器不关闭容器的方法

https://www.jianshu.com/p/b1ce248d2a42

 

docker 后台运行和进入后台运行的容器

 

Docker 拉取 oracle 11g镜像配置

 https://blog.csdn.net/qq_38380025/article/details/80647620?tdsourcetag=s_pcqq_aiomsg

 

宿主机和docker之间时间差异问题

https://www.jianshu.com/p/0231568ab335

 

docker中文社区:

https://www.runoob.com/docker/centos-docker-install.html

 

查看Docker镜像仓库中镜像的所有标签

https://blog.csdn.net/weixin_33713707/article/details/87334023

二、docker安装

两种方式安装。

1、正常安装

https://www.runoob.com/docker/centos-docker-install.html

2、通过rpm安装

首先我们去Docker官网下载(docker-ce-18.06.1.ce-3.el7.x86_64.rpm)rpm包,地址 : https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

这里下载时,要下载3个包:

 

 进入到安装包所在路径,执行 sudo yum install *.rpm 命令进行安装。安装好之后设置docker开机自动启动和启动服务 命令 :sudo systemctl enable docker 。

 

二、Docker安装vsftpd:

Dockerfile:

FROM centos:7
MAINTAINER jason2019
RUN yum install -y vsftpd
#RUN mkdir -p /data/ftp
RUN useradd -d /data/ftp -s /bin/bash ROOT -p ROOT
RUN echo "ROOT:ROOT" | chpasswd
RUN chmod 755 /data/ftp
EXPOSE 20 21
ENTRYPOINT /usr/sbin/vsftpd && tail -f /etc/passwd
#RUN systemctl start vsftp.service

 

vsftpd.conf:

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
anon_root=/data/ftp
no_anon_password=YES
#local_root=/data/ftp
#ftp_username=ROOT
pasv_enable=YES
pasv_min_port=21100
pasv_max_port=21110
View Code

 

构建命令:

docker build -t ftp:1.0 .
docker run -dit -p 21:21 -p 20:20 -p 21100-21110:21100-21110 -v /data/vsftpd.conf:/etc/vsftpd/vsftpd.conf -v /data/ftp:/data/ftp --name ftp ftp:1.0

 

如果要支持匿名访问和上传,可参考以下文章:

Linux上的ftp服务器 vsftpd 之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传

 

三、安装mysql:

宿主机上先新建三个目录:

conf、data、logs。

 

docker run -it --network=host --name mysql1.1 -v /home/upload/mysql/conf:/etc/mysql/conf.d -v /home/upload/mysql/logs:/logs -v /home/upload/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

参考:https://www.runoob.com/docker/docker-install-mysql.html

这里面几个选项的意思是:

-it 交互式执行

--network=host 使用主机的网络,这样做的效果是,不需要映射端口了

-v  /home/upload/mysql/conf:/etc/mysql/conf.d  冒号前为宿主机路径,冒号后为容器路径,该选项将宿主机路径挂载到容器的对应路径下

-e 指定环境变量,这里如果发现宿主机和容器有时间差,可以传 -e TZ='Asia/Shanghai'

-d 指定镜像名:镜像版本(即tag)

 

四、从容器生成镜像

有时候,进入容器(假设基于镜像A)后,改了东西,退出容器后,内容还在。但是如果基于镜像A,再启动一个容器,里面是不包含前面修改的内容的,此时我们可以将修改后的A容器,保存为一个新的image.

docker commit -m 'tomcat-v1.5' tomcat1.4 tomcat:v1.5

-m指定注释,后面的tomcat1.4为当前要保存的容器的名字, tomcat:v1.5为新镜像的名字和tag。

 

五、安装tomcat

docker run  --network=host  -dit --name tomcat1.4 -v /home/upload/tomcat/webapps:/home/upload/apache-tomcat-8.5.28/webapps  tomcat:1.4 

其中镜像tomcat1.4是自己拉了centos后,自己进去安装后,保存的。

 

六、安装rabbitmq

https://blog.csdn.net/bksqmy/article/details/95459256

命令我稍微修改了一下:

docker run -d --name rabbitmq3.7.7 --network=host -v `pwd`/data:/var/lib/rabbitmq --hostname myRabbit -e RABBITMQ_DEFAULT_VHOST=my_vhost  -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin rabbitmq:3.7.7-management

 

六、docker安装nginx

https://www.runoob.com/docker/docker-install-nginx.html

基于以上文章,但是要真实映射本地文件,通过http来访问的话,文章里的配置是不够的,还需要做以下配置:

 docker run -d  --network=host  --name nginx -v /home/ceiec/upload/nginx/pas-all-webapp:/usr/nginx/pas-all-webapp -v /home/ceiec/upload/nginx/www:/usr/share/nginx/html -v /home/ceiec/upload/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/ceiec/upload/nginx/logs:/var/log/nginx nginx

 

以上标红表示,将本地的 /home/ceiec/upload/nginx/pas-all-webapp 映射到 docker容器的 /usr/nginx/pas-all-webapp 目录。

在宿主机是这样的:

 

此时,需要在nginx.conf作如下配置(标红处,路径都是容器内的路径):

server {
        listen       9000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /pwc {
            root   /usr/nginx/pas-all-webapp;
            index  index.html;
        }
        location /bdmp {
            root   /usr/nginx/pas-all-webapp;
            index  index.html;
        }
}

 

六、docker镜像的迁移(一台主机的镜像导出到另一台)

分两步。

1、在源机器上,将image保存为tar

docker save -O oracle_config_ok:latest ./oracle_config_ok.tar

2、在目标机器上,将tar导入

docker load -i oracle_config_ok.tar

 

posted @ 2019-07-15 15:33  三国梦回  阅读(280)  评论(0)    收藏  举报