Docker
来自Ubuntu中文
跳到导航跳到搜索
安装
sudo apt-get install apt-transport-https ca-certificates sudo apt-key adv \ --keyserver hkp://ha.pool.sks-keyservers.net:80 \ --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list sudo apt-get update sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual sudo apt-get install docker-engine sudo service docker start
安装 portainer 面板
docker run -d -p 9000:9000 portainer/portainer
安装网络
git clone https://github.com/jpetazzo/pipework.git sudo cp ./pipework/pipework /usr/local/bin/ sudo apt-get install iputils-arping bridge-utils -y # 注意配置这个会断网 sudo brctl addbr br0 sudo ip addr add 192.168.1.4/24 dev br0 sudo ip addr del 192.168.1.4/24 dev eno1 sudo ip link set dev br0 up sudo brctl addif br0 eno1 sudo ip route del default sudo ip route add default via 192.168.1.1 dev br0
# echo 'DOCKER_OPTS="-b=br0"' >> /etc/default/docker # 设置这个需要关闭掉默认的 docker0 ,否则默认还是会走这个。 sudo docker ps sudo pipework br0 test1 192.168.1.10/24
主机网络配置参考
cat /etc/network/interfaces
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto eno1 #iface eno1 inet dhcp auto br0 iface br0 inet static address 192.168.1.233 netmask 255.255.255.0 gateway 192.168.1.3 bridge_ports eno1 bridge_stp off dns-nameservers 192.168.1.3 192.168.1.2
# 可以指定容器的网络网关为服务器的IP,当然也可以不用指定,直接使用内部默认的网关172.17.0.1。 ## pipework br0 -i eth1 test4 192.168.1.11/[email protected] # pipework br0 -i eth1 test4 192.168.1.11/24
安装私有仓库
sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2
需要修改客户端允许上传到这个私有仓库
cat /etc/docker/daemon.json
{ "insecure-registries": ["192.168.1.233:5000"] }
制作镜像
sudo pip install --upgrade pip sudo pip install -U docker-compose
制作jboss wildfly镜像
Dockerfile 文件内容如下
FROM jboss/wildfly:8.1.0.Final ENV POSTGRESQL_VERSION 9.4-1201-jdbc41 ENV JBOSS_HOME /opt/jboss/wildfly ARG DB_HOST=postgres ARG DB_NAME=postgres ARG DB_USER=postgres ARG DB_PASS=postgres ARG JNDI_NAME=jndi-name RUN $JBOSS_HOME/bin/add-user.sh admin -p admin -s RUN /bin/sh -c '$JBOSS_HOME/bin/standalone.sh &' && \ sleep 10 && \ cd /tmp && \ curl --location --output postgresql-${POSTGRESQL_VERSION}.jar --url http://search.maven.org/remotecontent?filepath=org/postgresql/postgresql/${POSTGRESQL_VERSION}/postgresql-${POSTGRESQL_VERSION}.jar && \ $JBOSS_HOME/bin/jboss-cli.sh --connect --command="deploy /tmp/postgresql-${POSTGRESQL_VERSION}.jar" && \ $JBOSS_HOME/bin/jboss-cli.sh --connect --command="xa-data-source add --name=${JNDI_NAME} --jndi-name=java:/${JNDI_NAME} --user-name=${DB_USER} --password=${DB_PASS} --driver-name=postgresql-${POSTGRESQL_VERSION}.jar --xa-datasource-class=org.postgresql.xa.PGXADataSource --xa-datasource-properties=ServerName=${DB_HOST},PortNumber=5432,DatabaseName=${DB_NAME} --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter" && \ $JBOSS_HOME/bin/jboss-cli.sh --connect --command=:shutdown && \ rm -rf $JBOSS_HOME/standalone/configuration/standalone_xml_history/ $JBOSS_HOME/standalone/log/* && \ rm /tmp/postgresql-9.4*.jar && \ rm -rf /tmp/postgresql-*.jar COPY *.ear $JBOSS_HOME/standalone/deployments/ EXPOSE 8080 9990 CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-Djboss.http.port=8080"]
打包为镜像:
sudo docker build -t esp --build-arg JNDI_NAME=esp . # sudo docker build --build-arg DB_HOST=db --build-arg DB_NAME=postgres --build-arg DB_USER=postgres --build-arg DB_PASS=postgres .
运行镜像测试,依赖poestgres数据库,主机为db:
sudo docker run -t -i --link postgres:postgres esp # sudo docker run -t -i -name esp --link db:postgres esp
上传到私有仓库:
sudo docker tag esp 192.168.1.233:5000/esp sudo docker push 192.168.1.233:5000/esp
参考地址
https://docs.docker.com/engine/installation/linux/ubuntulinux/
http://portainer.io/install.html
https://toutiao.io/posts/496585/app_preview
https://opskumu.gitbooks.io/docker/content/chapter6.html
http://www.linuxidc.com/Linux/2015-02/113783.htm
https://yeasy.gitbooks.io/docker_practice/content/
https://github.com/docker/docker.github.io/blob/master/registry/deploying.md
链接
其他客户端初始命令
sed -i "s/archive.ubuntu.com/mirrors.163.com/" /etc/apt/sources.list apt-get update apt-get install net-tools iputils-ping