Wednesday 8 June 2022

Publishing Ports in Docker Container

Publish a swarm service’s port using the Routing Mesh

sudo docker swarm init

Swarm initialized: current node (vnn5llqhowzrwgfh5qikwsp3q) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-1zzixogfyzyamjls1f1bv2rjlisx6knsozo36oknw6yo5psye1-dbwao0lok6qzm3ao9rg0lgo7n

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

 sudo docker service create --mode replicated --name service_1 --publish 8080:80 --replicas 3 nginx


overall progress: 3 out of 3 tasks

1/3: running   [==================================================>]

2/3: running   [==================================================>]

3/3: running   [==================================================>]

verify: Service converged

 sudo docker ps

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES

f356a36055b5   nginx:latest   "/docker-entrypoint.…"   40 seconds ago   Up 36 seconds   80/tcp    service_1.3.lppzun8l23ccc1jngnnx98v82

d6f230e2ca9e   nginx:latest   "/docker-entrypoint.…"   40 seconds ago   Up 36 seconds   80/tcp    service_1.1.nre4eqqptie7lbi8gtoxen3ln

bd8799737fb1   nginx:latest   "/docker-entrypoint.…"   40 seconds ago   Up 36 seconds   80/tcp    service_1.2.n1882s4tgfm8wdjagfuj6lqpt

sudo docker network ls

NETWORK ID     NAME              DRIVER    SCOPE

58866427dd61   bridge            bridge    local

f588c89e342e   host              host      local

p0u5qgqcq8ui   ingress           overlay   swarm

40e61f80d7dd   none              null      local

curl localhost:8080

<!DOCTYPE html>



<h1>Welcome to nginx!</h1>




Publish a swarm service’s port directly on the swarm node

 sudo docker service create --mode global --publish 8081:80 --name=service2 nginx:latest


overall progress: 1 out of 1 tasks

vnn5llqhowzr: running   [==================================================>]

verify: Service converged

 sudo docker ps

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES

5d97f7ebb808   nginx:latest   "/docker-entrypoint.…"   40 seconds ago   Up 39 seconds   80/tcp    service2.vnn5llqhowzrwgfh5qikwsp3q.uau42er9bwr22x8q4ealmhpvm

f356a36055b5   nginx:latest   "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp    service_1.3.lppzun8l23ccc1jngnnx98v82

d6f230e2ca9e   nginx:latest   "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp    service_1.1.nre4eqqptie7lbi8gtoxen3ln

bd8799737fb1   nginx:latest   "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes   80/tcp    service_1.2.n1882s4tgfm8wdjagfuj6lqpt

curl localhost:8081

<!DOCTYPE html>




<h1>Welcome to nginx!</h1>




sudo docker service ls

ID             NAME        MODE         REPLICAS   IMAGE          PORTS

k0gts8t7uifq   service2    global       1/1        nginx:latest   *:8081->80/tcp

2x1hxat4m68v   service_1   replicated   3/3        nginx:latest   *:8080->80/tcp

sudo docker service rm k0gts8t7uifq 2x1hxat4m68v



sudo docker container stop 5d97f7ebb808 f356a36055b5 d6f230e2ca9e bd8799737fb1





sudo docker image prune --force

Deleted Images:

untagged: nginx@sha256:2bcabc23b45489fb0885d69a06ba1d648aeda973fae7bb981bafbb884165e514

deleted: sha256:0e901e68141fd02f237cf63eb842529f8a9500636a9419e3cf4fb986b8fe3d5d

deleted: sha256:1e877fb1acf761377390ab38bbad050a1d5296f1b4f51878c2695d4ecdb98c62

deleted: sha256:834e54d50f731515065370d1c15f0ed47d2f7b6a7b0452646db80f14ace9b8de

deleted: sha256:d28ca7ee17ff94497071d5c075b4099a4f2c950a3471fc49bdf9876227970b24

deleted: sha256:096f97ba95539883af393732efac02acdd0e2ae587a5479d97065b64b4eded8c

deleted: sha256:de7e3b2a7430261fde88313fbf784a63c2229ce369b9116053786845c39058d5

deleted: sha256:ad6562704f3759fb50f0d3de5f80a38f65a85e709b77fd24491253990f30b6be

Total reclaimed space: 141.5MB

No comments:

Post a Comment