Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docpublic:systemes:docker_windows [2024/11/12 14:37]
adminjp [Astuce groupe docker]
docpublic:systemes:docker_windows [2024/11/12 18:13] (current)
adminjp [result]
Line 8: Line 8:
   * prerequisit Win Service Linux (WSL2) : https://learn.microsoft.com/en-us/windows/wsl/install   * prerequisit Win Service Linux (WSL2) : https://learn.microsoft.com/en-us/windows/wsl/install
   * docker desktop for windows https://www.docker.com/products/docker-desktop/ (create / sing in account)    * docker desktop for windows https://www.docker.com/products/docker-desktop/ (create / sing in account) 
 +  * VScodium file-code editor https://vscodium.com///
 +  * git https://git-scm.com/downloads/win
  
  
Line 21: Line 23:
 ===== docker terminal /shell =====  ===== docker terminal /shell ===== 
  
-<code> +==== list & get images ====
-C:\Users\jehan>docker ps +
-CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES+
  
 +<code>
 C:\Users\jehan>docker images C:\Users\jehan>docker images
 REPOSITORY   TAG       IMAGE ID   CREATED   SIZE REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
Line 47: Line 48:
 REPOSITORY   TAG       IMAGE ID       CREATED       SIZE REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
 nginx        1.27.2    60c8a892f36f   5 weeks ago   192MB nginx        1.27.2    60c8a892f36f   5 weeks ago   192MB
 +</code>
 +
 +==== run images ====
 +
 +running an image creates a instance of the image = container 
 +
 +<code>
 +C:\Users\jehan>docker run nginx:1.27.2
 +/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
 +/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
 +10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
 +10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
 +/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
 +/docker-entrypoint.sh: Configuration complete; ready for start up
 +2024/11/12 14:38:28 [notice] 1#1: using the "epoll" event method
 +2024/11/12 14:38:28 [notice] 1#1: nginx/1.27.2
 +2024/11/12 14:38:28 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
 +2024/11/12 14:38:28 [notice] 1#1: OS: Linux 5.15.153.1-microsoft-standard-WSL2
 +2024/11/12 14:38:28 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
 +2024/11/12 14:38:28 [notice] 1#1: start worker processes
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 29
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 30
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 31
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 32
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 33
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 34
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 35
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 36
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 37
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 38
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 39
 +2024/11/12 14:38:28 [notice] 1#1: start worker process 40
 +
 +dans un autre terminal 
 +
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS     NAMES
 +3c24edd9cc6d   nginx:1.27.2   "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   80/tcp    xenodochial_babbage
 +</code>
 +
 +=== run ct as daemon === 
 + option //-d//
 +
 +<code>
 +C:\Users\jehan>docker run -d nginx:1.27.2
 +8aa18cfb6e51369a9d08463e24580c1eef308ed1f3f04bce324cb47760d1c831
 +
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
 +8aa18cfb6e51   nginx:1.27.2   "/docker-entrypoint.…"   54 seconds ago   Up 53 seconds   80/tcp    trusting_napier
 +</code>
 +
 +=== get log in daemon mode ===
 +
 +docker logs ct-ID
 +
 +<code>
 +C:\Users\jehan>docker logs 8aa18cfb6e51369a9d08463e24580c1eef308ed1f3f04bce324cb47760d1c831
 +/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
 +/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
 +10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
 +10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
 +/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
 +/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
 +/docker-entrypoint.sh: Configuration complete; ready for start up
 +2024/11/12 14:42:30 [notice] 1#1: using the "epoll" event method
 +2024/11/12 14:42:30 [notice] 1#1: nginx/1.27.2
 +2024/11/12 14:42:30 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
 +2024/11/12 14:42:30 [notice] 1#1: OS: Linux 5.15.153.1-microsoft-standard-WSL2
 +2024/11/12 14:42:30 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
 +2024/11/12 14:42:30 [notice] 1#1: start worker processes
 +</code>
 +
 +
 +==== Network, expose port ====
 +
 +by default the 80 port is only exposed inside the CT, we have to export/expose it outside the CT by binding it to an external port, option  //-p 8080:80//  (a privilege dialog might open to allow firewall access) 
 +
 +<code>
 +C:\Users\jehan>docker stop 8aa18cfb6e51369a9d08463e24580c1eef308ed1f3f04bce324cb47760d1c831
 +8aa18cfb6e51369a9d08463e24580c1eef308ed1f3f04bce324cb47760d1c831
 +
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
 +
 +C:\Users\jehan>docker run -d -p 8080:80 nginx:1.27.2
 +70a30ce86f2fd3d8556e731487b9d0505dd9e54bc1de6ee7040889b0ca785447
 +</code>
 +
 +http://localhost:8080/
 +
 +==== list previous instances ====
 +
 +<code>
 +C:\Users\jehan>docker ps -a
 +CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                      PORTS                  NAMES
 +70a30ce86f2f   nginx:1.27.2   "/docker-entrypoint.…"   7 minutes ago    Up 7 minutes                0.0.0.0:8080->80/tcp   competent_austin
 +8aa18cfb6e51   nginx:1.27.2   "/docker-entrypoint.…"   16 minutes ago   Exited (0) 8 minutes ago                           trusting_napier
 +3c24edd9cc6d   nginx:1.27.2   "/docker-entrypoint.…"   20 minutes ago   Exited (0) 16 minutes ago                          xenodochial_babbage
 +</code>
 +
 +<code>
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                  NAMES
 +70a30ce86f2f   nginx:1.27.2   "/docker-entrypoint.…"   9 minutes ago   Up 9 minutes   0.0.0.0:8080->80/tcp   competent_austin
 +
 +C:\Users\jehan>docker stop 70a30ce86f2f
 +70a30ce86f2f
 +
 +C:\Users\jehan>
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
 +
 +C:\Users\jehan>docker ps -a
 +CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                      PORTS     NAMES
 +70a30ce86f2f   nginx:1.27.2   "/docker-entrypoint.…"   9 minutes ago    Exited (0) 5 seconds ago              competent_austin
 +8aa18cfb6e51   nginx:1.27.2   "/docker-entrypoint.…"   17 minutes ago   Exited (0) 10 minutes ago             trusting_napier
 +3c24edd9cc6d   nginx:1.27.2   "/docker-entrypoint.…"   21 minutes ago   Exited (0) 18 minutes ago             xenodochial_babbage
 +</code>
 +
 +it is more convenient to name CT instead of using random IDs, option //--name//
 +
 +<code>
 +C:\Users\jehan>docker run -d --name webApp -p 8080:80 nginx:1.27.2
 +fb93da95c41f639d38a08d06e39ff14da2144e1f3baa1a33d9fa7099a1c0c4cd
 +
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                  NAMES
 +fb93da95c41f   nginx:1.27.2   "/docker-entrypoint.…"   5 seconds ago   Up 4 seconds   0.0.0.0:8080->80/tcp   webApp
 +</code>
 +
 +===== own images =====
 +
 +==== online sample code ====
 +
 +get a source code example on a  nodeJS app from Nana
 +
 +<code>
 +jehan@G10JP24 MINGW64 ~/Documents/Progs-JP/docker-tuto-nana
 +$ git clone https://github.com/nomsynonso/techworld-js-docker-demo-app.git
 +Cloning into 'techworld-js-docker-demo-app'...
 +remote: Enumerating objects: 52, done.
 +remote: Counting objects: 100% (21/21), done.
 +remote: Compressing objects: 100% (6/6), done.
 +remote: Total 52 (delta 16), reused 15 (delta 15), pack-reused 31 (from 1)
 +Receiving objects: 100% (52/52), 5.80 MiB | 3.42 MiB/s, done.
 +Resolving deltas: 100% (21/21), done.
 +</code>
 +
 +from that sample code we creat an even simpler test code 
 +
 +==== source files my-app ====
 +
 +server.js simple node-js app, with associated package.json dependencies file and the Dockerfile defining how to build the image
 +
 +<code>
 +C:\Users\jehan\Documents\Progs-JP\docker-tuto-nana\AppJP>more src\server.js
 +const express = require('express');
 +const app = express();
 +
 +app.get('/', (req, res)=>{
 +    res.send("Welcome to JP App ! ");
 +  });
 +
 +app.listen(3000, function () {
 +  console.log("app JP listening on port 3000!");
 +});
 +
 +C:\Users\jehan\Documents\Progs-JP\docker-tuto-nana\AppJP>more package.json
 +{
 +  "name": "my-app-jp",
 +  "version": "1.0",
 +  "author": "Jehan",
 +  "license": "ISC",
 +  "dependencies": {
 +    "express": "4.18.2"
 +  }
 +}
 +
 +C:\Users\jehan\Documents\Progs-JP\docker-tuto-nana\AppJP>more Dockerfile
 +FROM node:19-alpine
 +
 +COPY package.json /app/
 +COPY src /app/
 +
 +WORKDIR /app
 +
 +RUN npm install
 +
 +CMD ["node", "server.js"]
 +
 +</code>
 +
 +==== build image ====
 +
 +<code>
 + Répertoire de C:\Users\jehan\Documents\Progs-JP\docker-tuto-nana\AppJP
 +
 +12/11/2024  18:35    <DIR>          .
 +12/11/2024  17:58    <DIR>          ..
 +12/11/2024  18:30               127 Dockerfile
 +12/11/2024  18:06               145 package.json
 +12/11/2024  18:35    <DIR>          src
 +               2 fichier(s)              272 octets
 +               3 Rép(s)  225 801 773 056 octets libres
 +
 +C:\Users\jehan\Documents\Progs-JP\docker-tuto-nana\AppJP>docker build -t node-app-jp:1.0 .
 +[+] Building 27.2s (10/10) FINISHED                                                                docker:desktop-linux
 + => [internal] load build definition from Dockerfile                                                               0.0s
 + => => transferring dockerfile: 164B                                                                               0.0s
 + => [internal] load metadata for docker.io/library/node:19-alpine                                                  0.5s
 + => [internal] load .dockerignore                                                                                  0.0s
 + => => transferring context: 2B                                                                                    0.0s
 + => [1/5] FROM docker.io/library/node:19-alpine@sha256:8ec543d4795e2e85af924a24f8acb039792ae9fe8a42ad5b4bf4c277a  22.4s
 + => => resolve docker.io/library/node:19-alpine@sha256:8ec543d4795e2e85af924a24f8acb039792ae9fe8a42ad5b4bf4c277ab  0.0s
 + => => sha256:d0ba7111bc031323ce2706f8e424afc868db289ba40ff55b05561cf59c123be1 1.16kB / 1.16kB                     0.0s
 + => => sha256:e2a8cc97f817417787050d381376568c494547f9af9decfca6463dee6db6561c 6.73kB / 6.73kB                     0.0s
 + => => sha256:8a49fdb3b6a5ff2bd8ec6a86c05b2922a0f7454579ecc07637e94dfd1d0639b6 3.40MB / 3.40MB                     2.9s
 + => => sha256:1197750296b3abe1d21ffbb3d3ea76df5ba887cf82c8e3284d267cbb2aa1724a 48.15MB / 48.15MB                  18.5s
 + => => sha256:f352bc07f19b43a8678cc8c8efe162ccb6193ead7af6dd366639a01402d1819e 2.34MB / 2.34MB                     3.0s
 + => => sha256:8ec543d4795e2e85af924a24f8acb039792ae9fe8a42ad5b4bf4c277ab34b62e 1.43kB / 1.43kB                     0.0s
 + => => extracting sha256:8a49fdb3b6a5ff2bd8ec6a86c05b2922a0f7454579ecc07637e94dfd1d0639b6                          0.1s
 + => => sha256:47be83a79857fb67c4d144471b8301ae6fb874971bfaa60d12dc97ea1355cffe 449B / 449B                         3.1s
 + => => extracting sha256:1197750296b3abe1d21ffbb3d3ea76df5ba887cf82c8e3284d267cbb2aa1724a                          3.2s
 + => => extracting sha256:f352bc07f19b43a8678cc8c8efe162ccb6193ead7af6dd366639a01402d1819e                          0.1s
 + => => extracting sha256:47be83a79857fb67c4d144471b8301ae6fb874971bfaa60d12dc97ea1355cffe                          0.0s
 + => [internal] load build context                                                                                  0.1s
 + => => transferring context: 242B                                                                                  0.0s
 + => [2/5] COPY package.json /app/                                                                                  0.2s
 + => [3/5] COPY src /app/                                                                                           0.1s
 + => [4/5] WORKDIR /app                                                                                             0.1s
 + => [5/5] RUN npm install                                                                                          3.4s
 + => exporting to image                                                                                             0.3s
 + => => exporting layers                                                                                            0.3s
 + => => writing image sha256:737409859eabee0fe209748239afd64912555929772792454bad0fe99e10da49                       0.0s
 + => => naming to docker.io/library/node-app-jp:1.0 
 +
 +</code>
 +
 +==== docker images my-node-app ====
 +
 +<code>
 +C:\Users\jehan>docker images
 +REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
 +node-app-jp   1.0       737409859eab   16 minutes ago   184MB
 +nginx         1.27.2    60c8a892f36f   5 weeks ago      192MB
 +</code>
 +
 +=== run it ===
 +
 +<code>
 +
 +C:\Users\jehan>docker run -d -p 3000:3000 node-app-jp:1.0
 +8dd672b044ce7d872004220a9f2128f8b4a701b2165bee94c19aa59acb4f8c95
 +
 +C:\Users\jehan>docker ps
 +CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS         PORTS                    NAMES
 +8dd672b044ce   node-app-jp:1.0   "docker-entrypoint.s…"   4 seconds ago   Up 3 seconds   0.0.0.0:3000->3000/tcp   focused_heyrovsky
 +
 +
 +C:\Users\jehan>docker logs 8dd672b044ce
 +app JP listening on port 3000!
 +</code>
 +
 +==== result ====
 +
 +navigate to http://localhost:3000/ , you'll see
 +
 +<code>
 +Welcome to JP App ! 
 +</code>
 +
 +===== docker compose =====
 +
 +manage multiple CT work together and in network 
 +
 +  * Nana tuto https://www.youtube.com/watch?v=SXwC9fSwct8
 +
 +
 +
 +==== network ====
 +
 +<code>
 +C:\Users\jehan>docker network create mongo-network
 +d8f44158f792089020aeac910d3c79c15664b11e668f054948e73095a8cf886b
 +
 +C:\Users\jehan>docker network ls
 +NETWORK ID     NAME            DRIVER    SCOPE
 +3d7e2cc5c6d6   bridge          bridge    local
 +067f0bdb2644   host            host      local
 +d8f44158f792   mongo-network   bridge    local
 +86943d7c1114   none            null      local
 </code> </code>
docpublic/systemes/docker_windows.1731422233.txt.gz · Last modified: 2024/11/12 14:37 by adminjp
[unknown link type]Back to top
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0