Exemple d’utilisation de Docker

Exemple d’utilisation de Docker.

1) Démarrage du service :

root@alarmpi ~]# systemctl start docker

2) Lancement automatique du service au démarrage du système :

[root@alarmpi ~]# systemctl enable docker
ln -s '/usr/lib/systemd/system/docker.service' '/etc/systemd/system/multi-user.target.wants/docker.service'

3) Création d’un fichier Docker :
Ouvrir :

Dockerfile

Ajouter :

FROM resin/rpi-raspbian
RUN apt-get update
RUN apt-get install -y openjdk-7-jre-headless wget
RUN wget -O /tmp/tomcat7.tar.gz http://mirror.cogentco.com/pub/apache/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz
RUN (cd /opt && tar zxf /tmp/tomcat7.tar.gz)
RUN (mv /opt/apache-tomcat* /opt/tomcat)
ENV JAVA_HOME /usr/lib/jvm/java-1.7.0-openjdk-armhf
RUN wget http://www.slashdot.org -P /opt/tomcat/webapps/slashdot
RUN wget http://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war -P /opt/tomcat/webapps
EXPOSE 8080
CMD ["/opt/tomcat/bin/catalina.sh", "run"]

4) Création du conteneur docker :

[root@alarmpi ~]# docker build -t tomcat .

5) Lancement du conteneur :

[root@alarmpi ~]# docker run -p 8080:8080 -d tomcat

6) Vérification :

[root@alarmpi ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
ee56d9f517a5        tomcat:latest       /opt/tomcat/bin/cata   9 minutes ago       Up 9 minutes        0.0.0.0:8080->8080/tcp   pensive_pike

7) Test :

http://192.168.1.20:8080/slashdot/

Ou
http://192.168.1.20:8080/sample/
8) Arrêter le conteneur :

[root@alarmpi ~]# docker stop ee56d9f517a5
ee56d9f517a5

9) Lister des images des conteneurs :

[root@alarmpi ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
tomcat                   latest              36d49f79eca9        14 minutes ago      455.6 MB
resin/rpi-raspbian       wheezy              3ec3d58821ee        5 months ago        160.3 MB
resin/rpi-raspbian       latest              808b368c3b55        5 months ago        178.4 MB
resin/rpi-raspbian       jessie              01992f5cb20d        6 months ago        175.7 MB
resin/rpi-google-coder   latest              4328ed7a471e        6 months ago        452.6 MB

10) Créer un compte sur Docker.io : https://www.docker.io/
11) Envoyer l’image vers Docker.io :
– Redémarrer le conteneur :

[root@alarmpi ~]# docker run -p 8080:8080 -d tomcat
77ea3d26dafe21dbb6130b7bffa10c76ba56b272a059212a12055e45be8d9f1d

– Lister les conteneurs :

[root@alarmpi ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
77ea3d26dafe        tomcat:latest       /opt/tomcat/bin/cata   21 seconds ago      Up 20 seconds       0.0.0.0:8080->8080/tcp   sharp_wilson

– Committer un conteneur :

[root@alarmpi ~]# docker commit 77ea3d26dafe nekrofage/tomcat
2f35ba10d08613839ad435fabb8c2700a1f61a171cb695b1b73e871ebb52457e

– Pousser le conteneur vers Docker.io :

[root@alarmpi ~]# docker push nekrofage/tomcat
The push refers to a repository [nekrofage/tomcat] (len: 1)
Sending image list
Please login prior to push:
Username: nekrofage
Password:
Email: contact@framboisepi.fr
Login Succeeded
The push refers to a repository [nekrofage/tomcat] (len: 1)
Sending image list
Pushing repository nekrofage/tomcat (1 tags)
Image 01992f5cb20d already pushed, skipping
Image 808b368c3b55 already pushed, skipping
Image 20048aeac529 already pushed, skipping
c14b2ec3f8da: Image successfully pushed
...
2f35ba10d086: Image successfully pushed
Pushing tag for rev [2f35ba10d086] on {https://registry-1.docker.io/v1/repositories/nekrofage/tomcat/tags/latest}

12) Repository du conteneur :
https://index.docker.io/u/nekrofage/
13) Lien :
http://blogs.infosupport.com/running-docker-0-9-on-a-raspberry-pi/
http://sametmax.com/le-deploiement-par-conteneurs-avec-docker/

Leave a Reply

You must be logged in to post a comment.