docker基础镜像操作实例

dockers基础操作

获取镜像:
docker pull alpine

查看镜像:
docker images

导出镜像:
docker save -o hello.jar hello

载入镜像:
docker load<hello.jar


运行一个镜像:
docker run -i -d -t hello /bin/bash

查看现有容器:
docker ps -a

删除容器:
docker rm 98c3a3c50dc9

删除镜像
docker rmi -f 98c3a3c50dc9

删除处于终止状态的所有容器:
docker rm 'docker ps -a -q'

停止容器:
docker stop 1219be7ea817

容器导出:
docker export cocky_agnesi >hello.tar.gz

容器导入:
cat hello.tar.gz | docker import - test/hello:v0.1

挂载本地配置文件到容器:
docker run -d -v /root/shoppingcart/config/(本地目录):/app/config/(容器目录) -v /root/shoppingcart/logs/service/:/logs/ -v /etc/hosts:/etc/hosts -p 9050:9050 shoppingcart/service:0.1 --spring.config.location=/app/config/service_e3.properties

build.sh文件
docker build -t leon/docker(镜像标签) /usr/local/apache/leon/docker (dockerfile的存放位置)

Dockerfile文件
FROM anapsix/alpine-java:latest

run.sh文件
docker run -i -d -t opt/test bin/bash

docker push address 将进行提交私有库

启动
 docker run -it docker.neg/ecbd/secureanalyze_consumer:1.0.9 /bin/sh

 进入容器:
 sudo docker ps -a
 sudo docker exec -it  04966500909c /bin/sh

 向私有仓库中push镜像
 docker push 172.30.10.203:5000/busybox

 修改tag
docker tag docker.io/anapsix/alpine-java 12.1.11.203:5000/docker.io/anapsix/alpine-java


build.sh

docker build -t docker.neg/ecbd/kafka:1.0.0 .

kafka docker镜像制作

//dockerfile
FROM docker.neg/base/alpine-java-jre:8

ADD kafka /opt/kafka/2.11-0.8.2.2
ADD start.sh /opt/kafka/2.11-0.8.2.2
VOLUME ["/opt/kafka/2.11-0.8.2.2/config"]
VOLUME ["/opt/kafka/2.11-0.8.2.2/data"]
VOLUME ["/opt/kafka/2.11-0.8.2.2/logs"]

WORKDIR /opt/kafka/2.11-0.8.2.2

CMD ["sh","start.sh"]
EXPOSE 9092

start.sh
option=
for arg in "$@"
do
        key=${arg%%=*}
        value=${arg#*=}
        case $key in
        --config)
                config=$value
                ;;
        esac
done
if [ ! -n $config ];then
        echo "config url must not null"
        exit 2
fi
echo "url=$config"
wget -O server.properties $config

if [ ! -f server.properties ];then
        echo "not find config server.properties"
        exit 2
fi
mv server.properties /opt/kafka/2.11-0.8.2.2/config

exec bin/kafka-server-start.sh config/server.properties

//远程server.properties内容
//./start.sh --config=http://1.1.1.1/bigdata/EC2Config/raw/master/Kafka/server_85.properties

elasticsearch docker镜像制作

//build.sh

docker build -t docker.neg/ecbd/elasticsearch :1.0.0 .

//docker file
#################################
#version: 1.01
#desc: es镜像
#es-version 2.3.2
#################################
FROM docker.neg/base/alpine-java-jre:8
MAINTAINER truman

ADD elasticsearch-2.3.2 /elasticsearch

# 挂载config和escluster
VOLUME ["/elasticsearch/config"]
VOLUME ["/elasticsearch/data"]
VOLUME ["/elasticsearch/logs"]

# 容器开放端口
EXPOSE 9200
EXPOSE 9300
WORKDIR /elasticsearch
CMD ["/elasticsearch/bin/elasticsearch"]

start.sh
option=
for arg in "$@"
do
        key=${arg%%=*}
        value=${arg#*=}
        case $key in
        --config)
                config=$value
                ;;
        esac
done
if [ ! -n $config ];then
        echo "config url must not null"
        exit 2
fi
echo "url=$config"
wget -O server.properties $config

if [ ! -f server.properties ];then
        echo "not find config server.properties"
        exit 2
fi
mv server.properties /opt/kafka/2.11-0.8.2.2/config

exec bin/kafka-server-start.sh config/server.properties

//start.sh
bash esManage.sh create http://1.1.1.1/bigdata/EC2Config/raw/master/Elasticsearch/gqc_cluster.json

猜你喜欢

转载自blog.csdn.net/qq_40990732/article/details/80880943
今日推荐