ubuntu docker镜像制作及常用命令

2023-12-18 15:00:45

ubuntu docker镜像制作及常用命令

一、安装docker

1、安装

sudo apt install docker.io

2、拉取ubuntu镜像

sudo docker pull ubuntu:18.04

3、从Dockerfile构建镜像

3.1、 Dockerfile示例
FROM ubuntu:18.04

MAINTAINER [user] [email]

RUN apt-get update \
        && apt-get install -y vim \
        && apt-get install -y git \
        && apt-get install -y cmake \
        && apt-get install -y g++ \
        && apt-get install -y python \
        && apt-get install -y python-pip \
        && apt-get install -y pytmote json config: conan rhon3 \
        && pip install conan \
        && cd /home \
        && git clone https://chromium.googlesource.com/chromium/tools/depot_tools \
        && echo "export PATH=/home/depot_tools:$PATH" >> ~/.bashrc \
        && apt-get install -y lsb-core \
        && apt-get install -y sudo \
        && apt-get install -y ssh \
        && mkdir /run/sshd \
        && apt-get install -y openjdk-8-jdk

CMD ["/usr/sbin/sshd", "-D"]
3.2、镜像编译编译
// 在Dockerfile目录执行
// 镜像名:tag, 不指定tag默认latest
sudo docker build -t docker_image_xxx:v1 .

二、运行容器

1、 普通运行

sudo docker run -it docker_image_xxx

2、指定目录运行

sudo docker run -it -v`pwd`:`pwd` docker_image_xxx

3、在容器中安装特定工具或命令

运行容器后,可以在容器中安特定工具和命令,再导出容器为镜像供其他人使用。

4 、导出容器为镜像

sudo docker commit 46bb44ef2f08 docker_image_xxx_new

46bb44ef2f08 为容器id
docker_image_xxx_new为新镜像名

三、导出镜像

sudo docker save docker_image_xxx_new > docker_image_xxx_new.tar

四、导入镜像

sudo docker load < docker_image_xxx_new.tar

文章来源:https://blog.csdn.net/weixin_36623563/article/details/135060816
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。