2017-10-07 3 views
0

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

Je suis en train d'importer l'image Ubuntu pour docker et installer des paquets serveral inscluding python3, PIP3, BS4 et PhantomJS. Ensuite, je veux enregistrer toutes ces configurations dans Docker comme "ubuntu-phantomjs". Comme je suis actuellement sur l'image Ubuntu, tout ce qui commence par la commande 'docker' ne fonctionne pas. Comment pourrais-je sauvegarder mon image?Comment faire pour enregistrer mes installations sur l'image Ubuntu en Docker

Répondre

1

Voici le 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/ 

Maintenant, après avoir sauvegardé le code dans le fichier nommé dockerfile, ouvrez un terminal dans le même répertoire que celui où le fichier est stocké, et commande suivante run:

$ docker build -t ubuntu-phantomjs . 

-t signifie que la cible est ubuntu-phantomjs et . signifie que le contexte de docker est le répertoire en cours. Le dockerfile ci-dessus n'est pas standard et ne respecte pas toutes les bonnes pratiques mentionnées here. Vous pouvez changer ce fichier en fonction de vos besoins, lisez les documentations pour plus d'aide.