博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker(6):获取和创建image
阅读量:4280 次
发布时间:2019-05-27

本文共 3684 字,大约阅读时间需要 12 分钟。

一、实现功能

获取image,或者实现自己制作Images。

二、获取image

1.通过dockerfile获取

(1)Dockerfile

more 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

三、制作base image

1.去除sudo,运行docker不需要sudo

(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

成功!

2.创建目录

[vagrant@localhost ~]$ mkdir hello-world[vagrant@localhost ~]$ cd hello-world/

3.创建c语言helloworld程序

[vagrant@localhost hello-world]$ vi hello.c

写入

#include
int main(){printf("hello docker");}

4.安装依赖

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

5.编译成可执行文件hello

gcc -static hello.c -o hello[vagrant@localhost hello-world]$ lshello  hello.c

测试执行文件

[vagrant@localhost hello-world]$ ./hellohello docker

6.当前目录创建dockerfile

创建base image

FROM scratch   #创建BaseimageADD hello /           #将可执行文件hello添加到image的根目录下CMD ["/hello"]        #执行根目录下的hello

7.制作docker image:spark/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

8.查看已有image

[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

9.查看image分层

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

10.创建docker容器

[vagrant@localhost hello-world]$ docker run spark/hello-worldhello docker

 

转载地址:http://egygi.baihongyu.com/

你可能感兴趣的文章
uImage 的 入口符号地址
查看>>
内核 镜像 解析
查看>>
getopt 解析
查看>>
文章标题
查看>>
linux前后台切换
查看>>
nmap
查看>>
uboot执行顺序main_loop
查看>>
uboot编译内容详解
查看>>
uboot Makefile 分析
查看>>
uboot网络验证
查看>>
烧写uboot
查看>>
QT安装
查看>>
QtCreator介绍
查看>>
QT工程实例
查看>>
pkg-config
查看>>
Linux内核分析-1/反汇编(堆栈)
查看>>
Linux内核分析-2/时间片轮转多道程序
查看>>
Linux内核分析-4/5/系统调用
查看>>
input 子系统(二) 杂谈
查看>>
input 子系统(三) 文件接口
查看>>