A recent project involved MongoDB clusters, Spark clusters, Hadoop clusters, Python 2.7, Python 3.5, various recommendation algorithms, Java Resin environment, LNMP environment, vsftpd, and more. Because it needed to be deployed across intranet, testing, and production environments, each deployment was painful. This is where Docker’s benefits really shone – packing Python environments, LNMP environments, vsftpd, and everything else into Docker containers was extremely satisfying. After 2 months of deployment and integration testing, I compiled some practical Docker commands. System environment: CentOS 7
Download, install Docker, and start the service
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
Download docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm1 2yum install docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm service docker startCommon Docker commands
Fix error: WARNING: IPv4 forwarding is disabled. Networking will not work.Step 1: On the host machine, run
echo "net.ipv4.ip_forward=1" >>/usr/lib/sysctl.d/00-system.confStep 2: Restart network and Docker services
1[root@localhost /]# systemctl restart network && systemctl restart dockerFailed to get D-Bus connection: Operation not permitted
1docker run -d --name centos7 --privileged=true --net=host -v /home/code:/home/code centos:mysql_python3_jdk1.8 /usr/sbin/initRun a Docker container for a long time with host path mounting
1docker run -dit -v /home/code:/home/code python35:latest /bin/bashEnter a running Docker container
1docker exec -it container_id /bin/bashStart a container image
1docker run -it python35:latest /bin/bashDocker export:
1docker export -o /home/python35.tar container_iddocker save *.tar
Docker import:
1docker import /home/python35.tardocker load < *.tar
Docker tagging
1docker tag image_id REPOSITORY:TAGDocker specify host network
1docker run -dit --net=host python35:latest /bin/bashDocker sync container and host time
1docker run -dit -v /etc/localtime:/etc/localtime python35:latest /bin/bashInstall JDK 1.8
1yum install java-1.8.0-openjdk* -yInstall MySQL 5.6
1 2 3 4 5 6 7 8rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yum -y install mysql-community-server systemctl enable mysqld systemctl start mysqld Initialize: mysql_secure_installation GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'remote_login_password' WITH GRANT OPTION; FLUSH PRIVILEGES;Python 3 encoding
1echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
| |