docker安装与启动

Storage Driver: devicemapper

Pool Name: docker-253:0-1792087-pool

Pool Blocksize: 65.54 kB

Base Device Size: 10.74 GB

Backing Filesystem: xfs

Data file: /dev/loop0

Metadata file: /dev/loop1

Data Space Used: 1.083 GB

Data Space Total: 107.4 GB

Data Space Available: 25.5 GB

Metadata Space Used: 1.278 MB

Metadata Space Total: 2.147 GB

Metadata Space Available: 2.146 GB

Udev Sync Supported: true

Deferred Removal Enabled: false

Deferred Deletion Enabled: false

Deferred Deleted Device Count: 0

Data loop file: /var/lib/docker/devicemapper/devicemapper/data

WARNING: Usage of loopback devices is strongly discouraged for production use. Either use --storage-opt dm.thinpooldev or use --storage-opt dm.no_warn_on_loop_devices=true to suppress this warning.

Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata

Library Version: 1.02.107-RHEL7 (2016-06-09)

Execution Driver: native-0.2

Logging Driver: journald

Plugins:

Volume: local

Network: bridge null host

Kernel Version: 3.10.0-327.28.2.el7.x86_64

Operating System: CentOS Linux 7 (Core)

OSType: linux

Architecture: x86_64

Number of Docker Hooks: 2

CPUs: 16

Total Memory: 15.66 GiB

Name: localhost.localdomain

ID: TWV7:7OXE:GGAN:MYFO:ERWM:FC2G:KCWJ:LSU6:TA4Y:Q6J6:ZK3I:GDB4

WARNING: bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-ip6tables is disabled

Registries: docker.io (secure)

docker镜像下载

=========================================================================

搜索可用的centos的docker镜像

[root@localhost /]# docker search centos//搜索centos镜像

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED

docker.io docker.io/centos The official build of CentOS. 2531 [OK]

docker.io docker.io/ansible/centos7-ansible Ansible on Centos7 82 [OK]

docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.8 x86_64 / CentOS-7 7.2.1511 x8… 27 [OK]

docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif… 13 [OK]

docker.io docker.io/million12/centos-supervisor Base CentOS-7 with supervisord launcher, h… 12 [OK]

docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS7 + Glus… 11 [OK]

docker.io docker.io/torusware/speedus-centos Always updated official CentOS docker imag… 8 [OK]

docker.io docker.io/nickistre/centos-lamp LAMP on centos setup 4 [OK]

docker.io docker.io/nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta… 3 [OK]

docker.io docker.io/consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co… 2 [OK]

docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]

docker.io docker.io/darksheer/centos Base Centos Image – Updated hourly 1 [OK]

docker.io docker.io/harisekhon/centos-java Java on CentOS (OpenJDK, tags jre/jdk7-8) 1 [OK]

docker.io docker.io/timhughes/centos Centos with systemd installed and running 1 [OK]

docker.io docker.io/aguamala/centos CentOS base image 0 [OK]

docker.io docker.io/dmglab/centos CentOS with some extras - This is for the … 0 [OK]

docker.io docker.io/grayzone/centos auto build for centos. 0 [OK]

docker.io docker.io/grossws/centos CentOS 6 and 7 base images with gosu and l… 0 [OK]

docker.io docker.io/harisekhon/centos-scala Scala + CentOS (OpenJDK tags 2.10-jre7 - 2… 0 [OK]

docker.io docker.io/januswel/centos yum update-ed CentOS image 0 [OK]

docker.io docker.io/jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0 [OK]

docker.io docker.io/kz8s/centos Official CentOS plus epel-release 0 [OK]

docker.io docker.io/repositoryjp/centos Docker Image for CentOS. 0 [OK]

docker.io docker.io/smartentry/centos CentOS with smartentry 0 [OK]

docker.io docker.io/ustclug/centos USTC centos 0 [OK]

构建docker镜像:

docker pull centos:laster

慢慢的等待镜像文件的下载。下载完可以通过如下命令查看镜像

docker images //查看镜像信息

REPOSITORY TAG IMAGE ID CREATED SIZE

docker.io/centos 7.2.1511 686672a1d0cc 5 weeks ago 194.6 MB

通过docker run来启动镜像,同时会创建一个容器,看下docker run的启动命令:

[root@localhost /]# docker run --help

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

Run a command in a new container

-a, --attach=[] Attach to STDIN, STDOUT or STDERR

–add-host=[] Add a custom host-to-IP mapping (host:ip)

–blkio-weight Block IO (relative weight), between 10 and 1000

–blkio-weight-device=[] Block IO weight (relative device weight)

–cpu-shares CPU shares (relative weight)

–cap-add=[] Add Linux capabilities

–cap-drop=[] Drop Linux capabilities

–cgroup-parent Optional parent cgroup for the container

–cidfile Write the container ID to the file

–cpu-period Limit CPU CFS (Completely Fair Scheduler) period

–cpu-quota Limit CPU CFS (Completely Fair Scheduler) quota

–cpuset-cpus CPUs in which to allow execution (0-3, 0,1)

–cpuset-mems MEMs in which to allow execution (0-3, 0,1)

-d, --detach Run container in background and print container ID

–detach-keys Override the key sequence for detaching a container

–device=[] Add a host device to the container

–device-read-bps=[] Limit read rate (bytes per second) from a device

–device-read-iops=[] Limit read rate (IO per second) from a device

–device-write-bps=[] Limit write rate (bytes per second) to a device

–device-write-iops=[] Limit write rate (IO per second) to a device

–disable-content-trust=true Skip image verification

–dns=[] Set custom DNS servers

–dns-opt=[] Set DNS options

–dns-search=[] Set custom DNS search domains

-e, --env=[] Set environment variables

–entrypoint Overwrite the default ENTRYPOINT of the image

–env-file=[] Read in a file of environment variables

–expose=[] Expose a port or a range of ports

–group-add=[] Add additional groups to join

-h, --hostname Container host name

–help Print usage

-i, --interactive Keep STDIN open even if not attached

–ip Container IPv4 address (e.g. 172.30.100.104)

–ip6 Container IPv6 address (e.g. 2001:db8::33)

–ipc IPC namespace to use

–isolation Container isolation level

–kernel-memory Kernel memory limit

-l, --label=[] Set meta data on a container

–label-file=[] Read in a line delimited file of labels

–link=[] Add link to another container

–log-driver Logging driver for container

–log-opt=[] Log driver options

-m, --memory Memory limit

–mac-address Container MAC address (e.g. 92:d0:c6:0a:29:33)

–memory-reservation Memory soft limit

–memory-swap Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap

–memory-swappiness=-1 Tune container memory swappiness (0 to 100)

–name Assign a name to the container

–net=default Connect a container to a network

–net-alias=[] Add network-scoped alias for the container

–oom-kill-disable Disable OOM Killer

–oom-score-adj Tune host’s OOM preferences (-1000 to 1000)

-P, --publish-all Publish all exposed ports to random ports

-p, --publish=[] Publish a container’s port(s) to the host

–pid PID namespace to use

–privileged Give extended privileges to this container

–read-only Mount the container’s root filesystem as read only

–restart=no Restart policy to apply when a container exits

–rm Automatically remove the container when it exits

–security-opt=[] Security Options

–shm-size Size of /dev/shm, default value is 64MB

–sig-proxy=true Proxy received signals to the process

–stop-signal=SIGTERM Signal to stop a container, SIGTERM by default

–sysctl=map[] Sysctl options

-t, --tty Allocate a pseudo-TTY

–tmpfs=[] Mount a tmpfs directory

-u, --user Username or UID (format: <name|uid>[:<group|gid>])

–ulimit=[] Ulimit options

–uts UTS namespace to use

-v, --volume=[] Bind mount a volume

–volume-driver Optional volume driver for the container

–volumes-from=[] Mount volumes from the specified container(s)

-w, --workdir Working directory inside the container

启动并创建一个交互式的docker容器:

[root@localhost /]# docker run -ti -d 686672a1d0cc

//-d为后台启动

通过docker ps 来查看当前运行的容器,看下docker ps的相关指令:

[root@localhost /]# docker ps --help

Usage: docker ps [OPTIONS]

List containers

-a, --all Show all containers (default shows just running)

-f, --filter=[] Filter output based on conditions provided

–format Pretty-print containers using a Go template

–help Print usage

-l, --latest Show the latest created container (includes all states)

-n=-1 Show n last created containers (includes all states)

–no-trunc Don’t truncate output

-q, --quiet Only display numeric IDs

-s, --size Display total file sizes

[root@localhost /]# docker ps//查看当前正在运行的容器

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

7d95b3df8674 686672a1d0cc “/bin/bash” 5 hours ago Up About an hour admiring_kowalevski

[root@localhost /]# docker ps -a//查看所有的容器信息

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

7d95b3df8674 686672a1d0cc “/bin/bash” 5 hours ago Up About an hour admiring_kowalevski

1b4ac575eda0 686672a1d0cc “/bin/bash” 23 hours ago Exited (137) About an hour ago elated_turing

通过docker start,docker stop来启动和停止容器:

[root@localhost /]# docker start --help

Usage: docker start [OPTIONS] CONTAINER [CONTAINER…]

Start one or more stopped containers

-a, --attach Attach STDOUT/STDERR and forward signals

–detach-keys Override the key sequence for detaching a container

–help Print usage

-i, --interactive Attach container’s STDIN

[root@localhost /]# docker stop --help

Usage: docker stop [OPTIONS] CONTAINER [CONTAINER…]

Stop a running container.

Sending SIGTERM and then SIGKILL after a grace period

–help Print usage

-t, --time=10 Seconds to wait for stop before killing it

[root@localhost /]# docker restart --help

Usage: docker restart [OPTIONS] CONTAINER [CONTAINER…]

Restart a container

–help Print usage

-t, --time=10 Seconds to wait for stop before killing the container

使用docker exec 可以进入到已经启动的容器中,低版本的docker可能不行。

[root@localhost Desktop]# docker exec -ti 7d95b3df8674 /bin/bash

[root@7d95b3df8674 /]#

容器的工作是建立在镜像的基础之上的,如果需要删除镜像的话,需要先删除使用该镜像的容器,然后才能删除镜像,否则删除镜像的时候,会有如下的类似的错误信息提示:Failed to remove image

(e7b): Error response from daemon: conflict: unable to delete e7b2de517efa (must be forced) - image is being used by stopped container 4fbc3cd00987,可以通过docker rm删除容器,docker rmi 删除镜像。

[root@localhost /]# docker rm --help

Usage: docker rm [OPTIONS] CONTAINER [CONTAINER…]

Remove one or more containers

-f, --force Force the removal of a running container (uses SIGKILL)

–help Print usage

-l, --link Remove the specified link

-v, --volumes Remove the volumes associated with the container

[root@localhost /]# docker rmi --help

Usage: docker rmi [OPTIONS] IMAGE [IMAGE…]

Remove one or more images

-f, --force Force removal of the image

–help Print usage

–no-prune Do not delete untagged parents

删除停止的容器

docker rm $(docker ps --all -q -f status=exited)

删除没有使用的镜像

docker rmi -f $(docker images | grep “” | awk “{print $3}”)

批量删除容器

docker ps -a | awk ‘{print $1}’ | xargs docker rm

批量删除镜像

docker images | awk ‘{print $3}’ | xargs docker rmi

持久化容器与镜像

1.通过容器生成新的镜像

运行中的镜像称为容器。你可以修改容器(比如删除一个文件),但这些修改不会影响到镜像。不过,你使用docker commit 命令可以把一个正在运行的容器变成一个新的镜像。

docker commit [repo:tag] 将一个container固化为一个新的image,后面的repo:tag可选。

2.持久化容器

docker export用于持久化容器。

[root@localhost /]# docker export --help

Usage: docker export [OPTIONS] CONTAINER

Export a container’s filesystem as a tar archive

–help Print usage

-o, --output Write to a file, instead of STDOUT

[root@localhost /]# docker export container.tar

3.持久化镜像

======================================================================

docker save用于持久化镜像:

[root@localhost /]# docker save --help

Usage: docker save [OPTIONS] IMAGE [IMAGE…]

Save an image(s) to a tar archive (streamed to STDOUT by default)

–help Print usage

-o, --output Write to a file, instead of STDOUT

[root@localhost /]# docker save image.tar

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Java)

最后

2020年在匆匆忙忙慌慌乱乱中就这么度过了,我们迎来了新一年,互联网的发展如此之快,技术日新月异,更新迭代成为了这个时代的代名词,坚持下来的技术体系会越来越健壮,JVM作为如今是跳槽大厂必备的技能,如果你还没掌握,更别提之后更新的新技术了。

更多JVM面试整理:

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
友,同时减轻大家的负担。**[外链图片转存中…(img-ay2DDiHV-1713825026596)]

[外链图片转存中…(img-8xJaKykE-1713825026597)]

[外链图片转存中…(img-anN6V0hw-1713825026597)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Java)

[外链图片转存中…(img-FXpjiQoX-1713825026598)]

最后

2020年在匆匆忙忙慌慌乱乱中就这么度过了,我们迎来了新一年,互联网的发展如此之快,技术日新月异,更新迭代成为了这个时代的代名词,坚持下来的技术体系会越来越健壮,JVM作为如今是跳槽大厂必备的技能,如果你还没掌握,更别提之后更新的新技术了。

[外链图片转存中…(img-ytQBqFBM-1713825026598)]

更多JVM面试整理:

[外链图片转存中…(img-3w9cgP6Z-1713825026599)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 29
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值