Windows11下Docker使用记录(二)

Docker使用记录(二)

    • [1. 常用指令](#1. 常用指令)
    • [2. Dockerfile示例](#2. Dockerfile示例)
    • [3. 构建docker image](#3. 构建docker image)

Docker中container,image,dockerfile

以及docker hub的关系如图所示,详细可见上一篇帖子。

本文主要记录Dockerfile相关。

1. 常用指令

常用指令(默认大写) 功能
FROM 指定基础镜像,位于Dockerfile第一行(必须有)FROM ubuntu:16.04
MAINTAINER 指定维护者信息(可以不写)MAINTAINER "test<[email protected]>"
COPY 和ADD相似,复制host中内容(必须与Dockerfile同级)至image指定路径中。COPY index.html /data/web/html/
ADD 同上。此外 ,如果source是URL或压缩包,会自动下载或自动解压 ADD http://nginx.org/download/nginx-1.15.8.tar.gz /usr/local/src/
WORKDIR 设置当前工作目录,为RUN,CMD等设置工作目录
ENV 定义所需的环境变量
RUN docker build过程中运行的程序,可以是任何命令 RUN cd ./src
EXPOSE 声明容器运行的服务端口,有tcp(默认)和udp EXPOSE 90/tcp
CMD 指定容器启动后默认运行的程序,CMD /usr/sbin/sshd -D(可以不写)

2. Dockerfile示例

python 复制代码
FROM ubuntu:16.04

# install ROS kinetic
RUN apt-get update \
    && apt-get -y install curl \
    && sh -c 'echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list' \
    && curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - \
    && apt-get update \
    && apt-get -y install ros-kinetic-desktop-full \
    && echo "source /opt/ros/kinetic/setup.bash" >> /etc/bash.bashrc \
    && /bin/bash -c '. /etc/bash.bashrc' \
    && apt-get -y install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential \
    && rosdep init \
    && rosdep update 
# create catkin_ws
RUN mkdir -p ~/catkin_ws/src \
    && cd ~/catkin_ws \
    # # ...
    # # do what you need to do for example git clone something into ~/catkin_ws/src
    # # ...
    && /bin/bash -c '. /opt/ros/kinetic/setup.bash; cd ~/catkin_ws; catkin_make; . ./devel/setup.bash'

3. 构建docker image

docker build
. 非常重要

bash 复制代码
docker build -t ubuntu-16.04:kinetic .

保存docker image至本地tar文件

bash 复制代码
docker save -o ubuntu-16.04:kinetic kinetic.tar

加载 tar文件到镜像

bash 复制代码
docker load -i kinetic.tar

参考文献:
1. https://www.cnblogs.com/edisonchou/p/dockerfile_inside_introduction.html
2. https://www.cnblogs.com/along21/p/10243761.html
3. http://t.csdnimg.cn/itVtL
4. http://t.csdnimg.cn/brVnu

相关推荐
项目題供诗4 小时前
黑马k8s(四)
云原生·容器·kubernetes
杰克逊的日记4 小时前
大项目k8s集群有多大规模,多少节点,有多少pod
云原生·容器·kubernetes
小张童鞋。4 小时前
k8s之k8s集群部署
云原生·容器·kubernetes
luck_me54 小时前
k8s v1.26 实战csi-nfs 部署
linux·docker·云原生·容器·kubernetes
邪恶的贝利亚4 小时前
《Docker 入门与进阶:架构剖析、隔离原理及安装实操》
docker·容器·架构
一直学下去5 小时前
K8S中构建双架构镜像-从零到成功
容器·kubernetes·cicd·多架构
知其_所以然5 小时前
使用docker安装clickhouse集群
clickhouse·docker·容器
hnlucky6 小时前
《基于 Kubernetes 的 WordPress 高可用部署实践:从 MariaDB 到 Nginx 反向代理》
运维·数据库·nginx·云原生·容器·kubernetes·mariadb
_板栗_7 小时前
livenessProbe 和 readinessProbe 最佳实践
云原生·容器·kubernetes
.生产的驴8 小时前
Docker 部署Nexus仓库 搭建Maven私服仓库 公司内部仓库
java·运维·数据库·spring·docker·容器·maven