如何将我在 Ubuntu 映像上的安装保存到 Docker 中



Docker Codes

# Import Ubuntu image to Docker
docker pull ubuntu:16.04
docker run -it ubuntu:16.04
# Instsall Python3 and pip3
apt-get update
apt-get install -y python3 python3-pip
# Install Selenium
pip3 install selenium
# Install BeautifulSoup4
pip3 install beautifulsoup4
# Install library for PhantomJS
apt-get install -y wget libfontconfig
# Downloading and installing binary
mkdir -p /home/root/src && cd &_
tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
cd phantomjs-2.1.1-linux-x86_64/bin/
cp phantomjs /usr/local/bin/
# Installing font
apt-get install -y fonts-nanum*

问题

我正在尝试将 Ubuntu 映像导入 docker 并安装包含 python3、pip3、bs4 和 PhantomJs 的服务器包。然后我想将 Docker 中的所有这些配置保存为"ubuntu-phantomjs"。由于我目前使用的是 Ubuntu 映像,因此任何以"docker"命令开头的内容都不起作用。如何保存我的图像?

这是 dockerfile:

# Import Ubuntu image to Docker
FROM ubuntu:16.04
# Install Python3, pip3, library and fonts
RUN apt-get update && apt-get install -y 
    python3 
    python3-pip 
    wget libfontconfig 
    fonts-nanum*
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install selenium beautifulsoup4
# Downloading and installing binary
RUN mkdir -p /home/root/src && cd &_ tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2 && cd phantomjs-2.1.1-linux-x86_64/bin/ && cp phantomjs /usr/local/bin/

现在将代码保存在名为 dockerfile 的文件中后,在与存储文件的目录相同的目录中打开一个终端,然后运行以下命令:

$ docker build -t ubuntu-phantomjs .

-t 表示目标ubuntu-phantomjs.表示 docker 的上下文是当前目录。上面的 dockerfile 不是标准的,并且不遵循此处提到的所有良好实践。您可以根据需要更改此文件,请阅读文档以获取更多帮助。

最新更新