本文共 3684 字,大约阅读时间需要 12 分钟。
获取image,或者实现自己制作Images。
1.通过dockerfile获取
(1)Dockerfilemore DockerfileFROM ubuntu:14.04LABEL maintainer=”Fresh New”RUN apt-get update && apt-get install -y redis-serverEXPOSE 6379ENTRYPOINT ["/usr/bin/stress"]CMD []
(2)通过当前Docker制作image
docker build -t xiaopeng163/redis:latest ./
2.直接通过Registry(中心)获取
网址:https://hub.docker.com/Docker pull ubuntu:14.04
(1)添加组
sudo groupadd docker
(2)添加密码
sudo gpasswd -a vagrant docker
(3)docker version
[vagrant@localhost ~]$ docker versionClient: Version: 18.09.6 API version: 1.39 Go version: go1.10.8 Git commit: 481bc77156 Built: Sat May 4 02:34:58 2019 OS/Arch: linux/amd64 Experimental: falseGot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/version: dial unix /var/run/docker.sock: connect: permission denied
(4)重启docker
sudo systemctl restart docker
(5)重新登录shell
exitvagrant sshPS D:\Program Files\dockerimage\centos7> vagrant sshLast login: Wed Jun 12 22:48:44 2019 from 10.0.2.2[vagrant@localhost ~]$ docker versionClient: Version: 18.09.6 API version: 1.39 Go version: go1.10.8 Git commit: 481bc77156 Built: Sat May 4 02:34:58 2019 OS/Arch: linux/amd64 Experimental: falseServer: Docker Engine - Community Engine: Version: 18.09.6 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 481bc77 Built: Sat May 4 02:02:43 2019 OS/Arch: linux/amd64 Experimental: false
成功!
[vagrant@localhost ~]$ mkdir hello-world[vagrant@localhost ~]$ cd hello-world/
[vagrant@localhost hello-world]$ vi hello.c
写入
#includeint main(){printf("hello docker");}
History | grep yumsudo yum install -y gitsudo yum install -y vimsudo yum install -y gccsudo yum install -y glibcsudo yum install -y locatesudo yum install -y glibc-static
gcc -static hello.c -o hello[vagrant@localhost hello-world]$ lshello hello.c
测试执行文件
[vagrant@localhost hello-world]$ ./hellohello docker
创建base image
FROM scratch #创建BaseimageADD hello / #将可执行文件hello添加到image的根目录下CMD ["/hello"] #执行根目录下的hello
#.表示当前目录[vagrant@localhost hello-world]$ docker build -f dockerfile.df -t spark/hello-world .Sending build context to Docker daemon 860.7kBStep 1/3 : FROM scratch --->Step 2/3 : ADD hello / ---> aeb23d00be47Step 3/3 : CMD ["/hello"] ---> Running in a4bc6efdc635Removing intermediate container a4bc6efdc635 ---> d801c21d3e64Successfully built d801c21d3e64Successfully tagged spark/hello-world:latest
[vagrant@localhost hello-world]$ docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEspark/hello-world latest d801c21d3e64 6 minutes ago 857kBhello-world latest fce289e99eb9 5 months ago 1.84kB
Docker history +iddocker history d801c21d3e64[vagrant@localhost hello-world]$ docker run spark/hello-worldhello docker[vagrant@localhost hello-world]$ docker history d801c21d3e64IMAGE CREATED CREATED BY SIZE COMMENTd801c21d3e64 10 hours ago /bin/sh -c #(nop) CMD ["/hello"] 0B aeb23d00be47 10 hours ago /bin/sh -c #(nop) ADD file:045c96be48d245ab8… 857kB
[vagrant@localhost hello-world]$ docker run spark/hello-worldhello docker
转载地址:http://egygi.baihongyu.com/