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

docker代码

# 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的多个包。 然后我想将所有这些configuration保存在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文件中dockerfile ,在与存储文件的目录相同的目录中打开terminal,然后运行以下命令:

 $ docker build -t ubuntu-phantomjs . 

-t表示目标是ubuntu-phantomjs. 意味着docker的上下文是当前目录。 上面的dockerfile不是标准的,不遵循这里提到的所有的好的做法。 您可以根据您的需要更改此文件,阅读文档以获取更多帮助。