docker常用操作

查看镜像列表:docker image ls

查看容器列表:docker ps

启动/创建容器:docker run [-itd] xxx [/bin/bash]  

-i:允许我们对容器内的 (STDIN) 进行交互
-t:在新容器内指定一个伪终端或终端
-d:后台运行
-v:是挂在宿机目录, /docker_test是宿机目录,/yufei是当前docker容器的目录,宿机目录必须是绝对的。
--name:是给容器起一个名字,可省略,省略的话docker会随机产生一个名字

进入容器打开shell:docker exec  -it xxx(容器id) [/bin/bash]

----------------------------------------------------------------------------------------------------------------

创建最小helloworld

Dockerfile :

FROM scratch
COPY hello /
CMD ["/hello"]

创建镜像:在Dockerfile所在目录,执行 docker build -t hello:1.0 .

----------------------------------------------------------------------------------------------------------------

从本地centos文件创建镜像:

FROM scratch
ADD centos-7.4.1708-docker.tar.xz /

LABEL name="CentOS Base Image" \
vendor="CentOS" \
license="GPLv2" \
build-date="20170911"

CMD ["/bin/bash"]

----------------------------------------------------------------------------------------------------------------

从docker仓库创建镜像:

FROM centos
MAINTAINER gavinhe gavinhe@tencent.com
RUN mkdir /data
COPY hello /data
ENTRYPOINT ["/data/hello", "gavin"]

----------------------------------------------------------------------------------------------------------------

上传镜像到腾讯云

登录:

docker login --username=100003767822 ccr.ccs.tencentyun.com

上传:

docker tag 9525a3d24b8b ccr.ccs.tencentyun.com/test_n/hello:3.1

docker push ccr.ccs.tencentyun.com/test_n/hello:3.1

----------------------------------------------------------------------------------------------------------------

去掉对共享库的依赖(可以使用scratch作为基础镜像):

[root@qcloud-gz1 helloworld]# go build
[root@qcloud-gz1 helloworld]#
[root@qcloud-gz1 helloworld]# ldd helloworld
linux-vdso.so.1 => (0x00007fffd7733000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f77b6a77000)
libc.so.6 => /lib64/libc.so.6 (0x00007f77b66aa000)
/lib64/ld-linux-x86-64.so.2 (0x00007f77b6c93000)
[root@qcloud-gz1 helloworld]#
[root@qcloud-gz1 helloworld]# CGO_ENABLED=0 go build
[root@qcloud-gz1 helloworld]#
[root@qcloud-gz1 helloworld]# ldd helloworld
not a dynamic executable
[root@qcloud-gz1 helloworld]#

posted @ 2018-11-16 19:26  gavinhe  阅读(171)  评论(0编辑  收藏  举报