There are some tutorials out there with running a nginx or a java webserver in a container but >100MB for each node seems far to much for my tests.
So i decided to create a application which listens on port 8080 with netcat. I created a directory ncweb with ncweb.sh:
ncweb# cat ncweb.shand a index.html:
#!/bin/bash
sed -i 's/Hostname:.*/Hostname: '$HOSTNAME'/g' index.html
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html;} | nc -l -p 8080; done 2&>1 >> logfile
ncweb# cat index.htmlThe Dockerfile looks like this:
<html>
<head>
<title>"Hello, World"</title>
</head>
<body bgcolor=white>
<table border="0" cellpadding="10">
<tr>
<td>
<h1>"Hello, World"</h1>
</td>
</tr>
</table>
</body>
</html>
# cat DockerfileAfter that i created the container:
FROM alpine
WORKDIR /tmp
ADD . /tmp
ENTRYPOINT [ "/tmp/ncweb.sh" ]
ncweb# docker build -t ncweb:0.2 .And let's do a test without docker swarm:
Sending build context to Docker daemon 4.096kB
Step 1/5 : FROM alpine
---> 053cde6e8953
Step 2/5 : WORKDIR /tmp
---> Using cache
---> c3e11ac3773b
Step 3/5 : RUN mkdir ncweb
---> Using cache
---> d9e634c03cd1
Step 4/5 : ADD . /tmp
---> 95f022aacc1c
Step 5/5 : ENTRYPOINT [ "/tmp/ncweb.sh" ]
---> Running in c1a9e8cee248
---> 6880521f68e4
Removing intermediate container c1a9e8cee248
Successfully built 6880521f68e4
Successfully tagged ncweb:0.2
ncweb# docker run -p 8080:8080 ncwebBut running this as a service fails:
# docker service create --replicas=1 --name myweb ncweb:0.2and:
image ncweb:0.2 could not be accessed on a registry to record
its digest. Each node will access ncweb:0.2 independently,
possibly leading to different nodes running different
versions of the image.
n0himwum38bqzd8ob1vf8zhip
overall progress: 0 out of 1 tasks
1/1: No such image: ncweb:0.2
^COperation continuing in background.
Use `docker service ps n0himwum38bqzd8ob1vf8zhip` to check progress.
# docker service ps n0himwum38bqzd8ob1vf8zhip
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
8tjsuae9jv8o myweb.1 ncweb:0.2 node01 Ready Rejected 3 seconds ago "No such image: ncweb:0.2"
qp24ssxb5bl5 \_ myweb.1 ncweb:0.2 alpine Shutdown Failed 36 seconds ago "task: non-zero exit (2)"
zwfgcatk7zyi \_ myweb.1 ncweb:0.2 node01 Shutdown Rejected about a minute ago "No such image: ncweb:0.2"
v4a7zkb85yd4 \_ myweb.1 ncweb:0.2 node01 Shutdown Rejected about a minute ago "No such image: ncweb:0.2"
ycjftjusv484 \_ myweb.1 ncweb:0.2 node01 Shutdown Rejected about a minute ago "No such image: ncweb:0.2"
# docker service rm n0himwum38bqzd8ob1vf8zhipThe error "No such image..." is happening, because the container ncweb is only in the repository of my master.
n0himwum38bqzd8ob1vf8zhip
The easiest way for my test environment is to distribute the local image to all nodes:
# docker save ncweb:0.3 | ssh 192.168.178.47 docker load(i have to distribute a ssh-key to all nodes)
The authenticity of host '192.168.178.47 (192.168.178.47)' can't be established.
ECDSA key fingerprint is SHA256:2/8O/SE1fGJ4f5bAQls5txrKMbqZfMmiZ+Tha/WFKxA.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.178.47' (ECDSA) to the list of known hosts.
root@192.168.178.47's password:
Loaded image: ncweb:0.3
and then:
alpine:~/ncweb# docker service create --replicas=1 --name myweb ncweb:0.3
image ncweb:0.3 could not be accessed on a registry to record
its digest. Each node will access ncweb:0.3 independently,
possibly leading to different nodes running different
versions of the image.
# docker service ps mywebSo my nc-webserver runs on node01, but i can not access it there because i did not define any port mappings ;-(
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
in97xlc7azcw myweb.1 ncweb:0.3 node01 Running Running 8 seconds ago
But finally this command did the job:
# docker service create --replicas=1 --name myweb --publish 8080:8080 ncweb:0.3The hostname corresponds to the docker container id on node01:
image ncweb:0.3 could not be accessed on a registry to record
its digest. Each node will access ncweb:0.3 independently,
possibly leading to different nodes running different
versions of the image.
runf8u9r8719sk13mkf8hh8ec
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
node01:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6c9434b08082 ncweb:0.3 "/tmp/ncweb.sh" 37 minutes ago Up 37 minutes myweb.1.lqiyb34cuxxme2141ahsg8neu
Remaining open points:
- Is it possible to do a failback or limit the number of a service per node?
- How to get a loadbalancing mechanism for a server application?
(load balancer needed?) - What happens, if the manager fails / is shutdown?
Related posts:
- Docker on Ubuntu
- Running through a tutorial / investigating the processes
- Creating a small linux for my docker cluster (Alpine Linux)
- How to build a docker swarm
- Creating a minimal webserver container and deploying it to docker swarm
- Setting up a tomcat with docker
- Running a swarm with multiple managers
- Mysql inside a docker container - persistency with docker volumes
- How to change the configuration of a standard docker container(e.g. changing tomcats memory settings)
Good information. Lucky me I ran across your website by accident (stumbleupon).
ReplyDeleteI have saved it for later!
Valuable post useful for everyone.Keep on sharing.
ReplyDeleteDocker and Kubernetes Training
Docker Online Training
Kubernetes Online Training