How to save my installations on Ubuntu image into Docker

Viewed 930

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*

Question

I am trying to import Ubuntu image to docker and install serveral packages inscluding python3, pip3, bs4, and PhantomJs. Then I want to save all this configurations in Docker as "ubuntu-phantomjs". As I am currently on Ubuntu image, anything that starts with 'docker' command do not work. How could I save my image?

1 Answers

Here is the 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/

Now after saving the code in file named dockerfile, open a terminal in the same directory as the one where file is stored, and run following command:

$ docker build -t ubuntu-phantomjs .

-t means that the target is ubuntu-phantomjs and . means that the context for docker is the current directory. The above dockerfile is not a standard one, and does not follow all good practices mentioned here. You can change this file according to your needs, read the documentations for more help.

Related