The web page is not displaying

Hello,

I’m looking to publish a web page using an HTTPD service created on the Docker Swarm’s node manager. The “It works” test page was initially displayed.

I modified the HTML file, but after restarting the container in Docker, the page no longer appears. A new container is automatically created, but it does not have the newly modified page.

How can I cancel the automatic creation of the container if it is causing the problem, or where else could the issue be?

Perhaps there is a network problem towards the outside?

Here is the Docker info. It is running on a container, and the main Docker is not in swarm mode.

 Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: p32xcdxp9jpcixnivxsbdeefw
  Is Manager: true
  ClusterID: x7p8x92uj8p3pglxyd3ewfas2
  Managers: 1
  Nodes: 3
  Default Address Pool: 10.0.0.0/8
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 172.17.0.2
  Manager Addresses:
   172.17.0.2:2377
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1677a17964311325ed1c31e2c0a3589ce6d5c30d
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-9-amd64
 Operating System: Alpine Linux v3.18 (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.921GiB
 Name: 0d1a98d8ea28
 ID: b5420e7d-e3d0-4cda-ba24-b0f252369f57
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

I edited your post. Please, next time format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

How exactly did you change the html file and how did you “restart” the container? You should not edit files directly inside containers. Instead, you can build a new Docker image and change the definition of the swarm service to use the new image. If you have multiple swarm nodes or you build the image on another machine, you should also have Docker registry.where you push you image and swarm can pull it from that registry. If you don’t do it this way and you kill the container, swarm will recreate it, because this is its job and the new container will not have any of the modifications you made in a previous container.

1 Like

Hello,
thank you for the explanations. I will make a note of the proper way to post.

Indeed, I made the mistake of modifying the file from within. Currently, I have set up a new swarm with an httpd service, but it is not displaying even though I have mapped it to port 80.

I don’t understand what’s happening because the first time I installed the “its works” container, it appeared. Here’s the error message:

Failed to connect to 192.168.X.X port 80 after 21002 ms: Couldn't connect to server.

docker info and docker network

Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: qqf1c0z0sfc8fu4ugtdlpcbnw
  Is Manager: true
  ClusterID: se4cq2jgorlkw5n4ey0ltk2tx
  Managers: 1
  Nodes: 4
  Default Address Pool: 10.0.0.0/8
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.1.32
  Manager Addresses:
   192.168.1.32:2377
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-9-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.921GiB
 Name: docker
 ID: 702766f5-b5de-49e8-99ba-b04d3a49d33a
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
root@docker:~# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
3aa11a6df455   bridge            bridge    local
129843f3c401   docker_gwbridge   bridge    local
e4895405eaf4   host              host      local
aj7gvj4k1ygh   ingress           overlay   swarm
d1983df3221d   none              null      local

Unfortunately the docker info and the list of networks will not help us to help you. Please, share codes and/or commands that shows your configuration and how you did what you think you did correctly.

I feel you also forgot to answer one of my questions:

It looks like now you have a completely new issue with port mappings.

PS.: Thank you for using code blocks! One more suggestion though: I edited your last post too because I barely noticed the end of the code block which is scrollable and when we think we know what the end of the code is, we might not scroll down so it is better to share outputs of different commands in multiple code blocks. Sometimes it is also useful to share the command in one codeblock and the output in another.

1 Like

Build the Docker Image

  1. Create a directory for your project and navigate into it.
  2. Create an HTML file (e.g., index.html) with your desired content.
  3. Create a Dockerfile (without any file extension) in the same directory and add the following content
  • FROM httpd:latest
    COPY ./index.html /usr/local/apache2/htdocs/
  1. Save the Dockerfile.
    Step 2: Build the Docker Image
    Step 3: Initialize Docker Swarm
    Step 4: Deploy the HTTPD Service
  • docker service create --name my-httpd-service --publish published=80,target=80,mode=ingress my-httpd-image
    Step 5: Access the Web Page
    Open a web browser and navigate to the IP address obtained in the previous step. You should see your web page displayed.
1 Like

Thank you for the explanations. I abandoned this conf for another one I hope you can help me.

Hello,
here is the configuration I made on docker swarm with stack on a cluster to create a wordpress site. I am having problems with the proxy configuration. I hope you can help me.
So I can’t view the web page.
Here are the config folders

docker-compose.yml

version: '3.7'

services:
  nginx:
    image: nginx:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    networks:
      - frontend


  wordpress:
    image: wordpress:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress_data:/var/www/html
    networks:
      - backend
      - frontend

  db:
    image: mysql:5.7
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - backend

networks:
   frontend:
   backend:

volumes:
  wordpress_data:
  db_data:


nginx.conf

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  server {
    listen 80;
    server_name greentravel.local;
    return 301 https://$host$request_uri;
  }

  server {
    listen 443 ssl;
    server_name greentravel.local;

    ssl_certificate /srv/certificates/wordpress.crt.pem;
    ssl_certificate_key /srv/certificates/wordpress.key.pem;

    location / {
      proxy_pass http://192.168.33.249;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  }
}

~                                                                        

docker stack ps wordpress

eygf18j19loh   wordpress_db.1              mysql:5.7          docker         Running         Running 11 minutes ago
trybstz9g1md    \_ wordpress_db.1          mysql:5.7          docker         Shutdown        Failed 11 minutes ago      "No such container: wordpress_…"
bzbhk6opnt4q    \_ wordpress_db.1          mysql:5.7          f68c22a21947   Shutdown        Ready 14 minutes ago
51w3b75wqjpy    \_ wordpress_db.1          mysql:5.7          851fc269c44d   Shutdown        Running 20 minutes ago
skojh124athm   wordpress_nginx.1           nginx:latest       docker         Ready           Ready 3 seconds ago
afmytf6q0tmg    \_ wordpress_nginx.1       nginx:latest       docker         Shutdown        Failed 4 seconds ago       "task: non-zero exit (1)"
od256h2dmd0c    \_ wordpress_nginx.1       nginx:latest       docker         Shutdown        Failed 11 seconds ago      "task: non-zero exit (1)"
4akf30sworis    \_ wordpress_nginx.1       nginx:latest       docker         Shutdown        Failed 17 seconds ago      "task: non-zero exit (1)"
wdu7sswunrh6    \_ wordpress_nginx.1       nginx:latest       docker         Shutdown        Failed 23 seconds ago      "task: non-zero exit (1)"
kflk7p6zef0t   wordpress_wordpress.1       wordpress:latest   docker         Running         Running 11 minutes ago
cwlzrfrfwzcm    \_ wordpress_wordpress.1   wordpress:latest   docker         Shutdown        Failed 11 minutes ago      "No such container: wordpress_…"
mk1t0y1lbkrc    \_ wordpress_wordpress.1   wordpress:latest   f68c22a21947   Shutdown        Preparing 14 minutes ago
fdyaj0f6ikyh    \_ wordpress_wordpress.1   wordpress:latest   32d020c2f434   Shutdown        Running 18 minutes ago

thanks in advance

What is this IP address? Is it the IP address of the container somehow? Note that when you are using containers that can be recreated you should use hostnames of the containers instead of IP addresses.

Since your containers are failing the first you should to is checking the logs.

https://docs.docker.com/engine/reference/commandline/service_logs/

But I’m not even sure you need the nginx proxy in that compose file if that is your only stack, since you could just use wordpress image which has Apache HTTPD.

1 Like

“Indeed, I changed the IP address to the container’s hostname afterwards, but I didn’t get any satisfactory results. So, I did it differently than you said. I simplified the configuration, and now it’s indicating that the database cannot be found. Could you please provide some assistance with this configuration?”

version: '3.7'

services:
  wordpress:
    depends_on:
     - db
    image: wordpress:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    ports:
      - 80:80
      - 443:443
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress_data:/var/www/html
    secrets:
       - source: wordpress.crt.pem
         target: /srv/certificates/wordpress.crt.pem
       - source: wordpress.key.pem
         target: /srv/certificates/wordpress.key.pem
    networks:
      - wp

  db:
    image: mysql:5.7
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - wp

networks:
   wp:
     external: true

volumes:
  wordpress_data:
  db_data:

secrets:
  wordpress.crt.pem:
    external: true
  wordpress.key.pem:
    external: true

I feel like I’m close, but not quite there yet. The page indicates that the database cannot be found. The services show that everything is okay. The database is in a node container, while WordPress is on a node manager, which is the main machine. I can’t add the node containers to WordPress without them going down.

error : Host '10.0.0.2' is not allowed to connect to this MySQL server

docker inspect ingress

[
    {
        "Name": "ingress",
        "Id": "6q3wlz6kr",
        "Created": "2",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": true,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "53d2ce1d458dfd16cfd5714677ace896dd1e462878410a1d7c3fab20097a15c0": {
                "Name": "wordpress_wordpr
                "EndpointID": "7b28b76662d99a8bb0d1f3600a65d4fd8306e87",
                "MacAddress": ":00:00:90",
                "IPv4Address": "10.0.0.144/24",
                "IPv6Address": ""
            },
            "6977495f269e097e59e74fd933884e60944e5b507cec61a": {
                "Name": "wordpress_db.1.bs60nks52nvq0yx6g60v122gu",
                "EndpointID": "3bf95cdaec3650bffa81355895cbf16527bbcc4a405058d295fdc074",
                "MacAddress": "0a:00:00:8d",
                "IPv4Address": "10.0.0.141/24",
                "IPv6Address": ""
            },
            "ingress-sbox": {
                "Name": "ingress-endpoint",
                "EndpointID": "38e497710cb96b5b809fe506ff57feb2ca8b5",
                "MacAddress": "a:00:00:02",
                "IPv4Address": "10.0.0.2/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4096"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "91bf95bf",
                "IP": "192.168.33.250"
            
            {
                "Name": d481fbb0b",
                "IP": "172.17.0.4"
            },
            {
                "Name": "df52b43",
                "IP": "172.17.0.3"
            },
            {
                "Name": "0f306cfb1",
                "IP": "172.17.0.2"
            }
        ]
    }
]

Thanks for help

after observation, I see that my database is not being created.

Finally, I managed to set up this configuration that works with HTTP. However, I am unable to get the self-signed SSL certificates to work. Does this configuration work with Docker stack? Can anyone see anything wrong with it?

version: '3.7'

services:
  wordpress:
    depends_on:
     - db
    image: wordpress:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    ports:
      - 80:80
      - 443:443
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: XXXX
      WORDPRESS_DB_PASSWORD: XXX
      VIRTUAL_HOST: XXX
      LETSENCRYPT_HOST: XXX
      LETSENCRYPT_EMAIL:XXXX
    volumes:
      - wp_html:/var/www/html
    secrets:
      - source: wordpress.crt.pem
        target: /srv/certificates/wordpress.crt.pem
      - source: wordpress.key.pem
        target: /srv/certificates/wordpress.key.pem
    networks:
      - wp

  db:
    image: mysql:5.7
    deploy:
      replicas: 1
      restart_policy:
        condition: any
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: XX
      MYSQL_DATABASE:XXX
      MYSQL_USER: XXX
      MYSQL_PASSWORD: XXXX
    volumes:
      - wp_db:/var/lib/mysql
    networks:
      - wp

networks:
   wp:
     driver: overlay

volumes:
  wp_db:
  wp_html:

secrets:
  wordpress.crt.pem:
    external: true
  wordpress.key.pem:
    external: true

SSL/TLS has nothing to do with Docker. You need to configure the application in the container to use a certificate.

Do you have error messages in this case?
And how did you configure Wordpress to use the certificates?