1

I have a simple "Hello, world!" Rust project. This is Dockerfile:

FROM alpine:3
EXPOSE 8080
WORKDIR /app
COPY target/release/actixblog /app
RUN ls /app
CMD /app/actixblog

This is .docker.env file:

POSTGRES_PASSWORD=111111
POSTGRES_USER=blogger
POSTGRES_DB=actixblog

And this is docker-compose.yaml:

version: "3.9"
services:
  web:
    image: "actixblog:latest"
    ports:
      - "8080:8080"
    depends_on:
      redisserver:
        condition: service_started
      psqlserver:
        condition: service_started
    networks:
      - redis-net
      - psql-net
  redisserver:
    image: redis:7-alpine
    restart: always
    networks:
      - redis-net
  psqlserver:
    image: postgres:14-alpine
    restart: always
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_DB=${POSTGRES_DB}
    networks:
      - psql-net
networks:
  redis-net:
  psql-net:

I do this in order:

cargo build --release
docker build -t actixblog . --no-cache
docker-compose --env-file .docker.env up --remove-orphans

I confirm that I successfully copied the compiled file to the image with RUN ls /app in Dockerfile. Here's the output of build:

Sending build context to Docker daemon  10.43MB
Step 1/6 : FROM alpine:3
 ---> 9c6f07244728
Step 2/6 : EXPOSE 8080
 ---> Running in 71a310317052
Removing intermediate container 71a310317052
 ---> 3e085d2525e3
Step 3/6 : WORKDIR /app
 ---> Running in c560186f4081
Removing intermediate container c560186f4081
 ---> c89bfb7c0328
Step 4/6 : COPY target/release/actixblog /app
 ---> 0db564fd359e
Step 5/6 : RUN ls -al /app
 ---> Running in 193c5fa9e574
total 3748
drwxr-xr-x    1 root     root            18 Sep 28 09:26 .
drwxr-xr-x    1 root     root             0 Sep 28 09:26 ..
-rwxr-xr-x    1 root     root       3836424 Sep 27 23:05 actixblog
Removing intermediate container 193c5fa9e574
 ---> 80ae58f944e9
Step 6/6 : CMD /app/actixblog
 ---> Running in fd8726ef4aeb
Removing intermediate container fd8726ef4aeb
 ---> bbb745d30b27
Successfully built bbb745d30b27
Successfully tagged actixblog:latest

And here's Docker Compose output:

Starting actixblog_redisserver_1 ... done
Starting actixblog_psqlserver_1  ... done
Recreating actixblog_web_1       ... done
Attaching to actixblog_redisserver_1, actixblog_psqlserver_1, actixblog_web_1
psqlserver_1   | 
psqlserver_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
psqlserver_1   | 
psqlserver_1   | 2022-09-28 08:57:56.410 UTC [1] LOG:  starting PostgreSQL 14.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
psqlserver_1   | 2022-09-28 08:57:56.410 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
psqlserver_1   | 2022-09-28 08:57:56.410 UTC [1] LOG:  listening on IPv6 address "::", port 5432
psqlserver_1   | 2022-09-28 08:57:56.444 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
psqlserver_1   | 2022-09-28 08:57:56.452 UTC [22] LOG:  database system was shut down at 2022-09-28 08:57:26 UTC
psqlserver_1   | 2022-09-28 08:57:56.507 UTC [1] LOG:  database system is ready to accept connections
web_1          | /bin/sh: /app/actixblog: not found
redisserver_1  | 1:C 28 Sep 2022 08:57:55.368 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redisserver_1  | 1:C 28 Sep 2022 08:57:55.368 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redisserver_1  | 1:C 28 Sep 2022 08:57:55.368 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redisserver_1  | 1:M 28 Sep 2022 08:57:55.368 * Increased maximum number of open files to 10032 (it was originally set to 1024).
redisserver_1  | 1:M 28 Sep 2022 08:57:55.368 * monotonic clock: POSIX clock_gettime
redisserver_1  | 1:M 28 Sep 2022 08:57:55.369 * Running mode=standalone, port=6379.
redisserver_1  | 1:M 28 Sep 2022 08:57:55.369 # Server initialized
redisserver_1  | 1:M 28 Sep 2022 08:57:55.369 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * Loading RDB produced by version 7.0.5
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * RDB age 29 seconds
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * RDB memory usage when created 0.82 Mb
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * Done loading RDB, keys loaded: 0, keys expired: 0.
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * DB loaded from disk: 0.000 seconds
redisserver_1  | 1:M 28 Sep 2022 08:57:55.370 * Ready to accept connections
actixblog_web_1 exited with code 127
^CGracefully stopping... (press Ctrl+C again to force)
Stopping actixblog_redisserver_1 ... done
Stopping actixblog_psqlserver_1  ... done

You can probably see web_1 | /bin/sh: /app/actixblog: not found above. So, it acts like there's no binary.

I expect it to run and print "Hello world!". Why can't ı run the binary?

Thanks in advance.


Environment

Docker version 20.10.14, build a224086349
docker-compose version 1.29.2, build unknown
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
  • A few things to check ... is the file you expect actually there in the image? Is it executable? Is it the right type of binary (built on the right platform, etc.) for the image? Try adding a ``RUN ls -al /app`` to check the first two of those things and show the output (you have a ``RUN ls /app`` in there already, but you don't show that output). – JohnXF Sep 28 '22 at 09:20
  • I have updated the question. As you can see from the output, the binary is there. – Eray Erdin Sep 28 '22 at 09:23
  • Add the ``-al`` options so you can see who owns the file and what permissions it has. It will need to be executable for a start, and executable by the container runner (root?) too. – JohnXF Sep 28 '22 at 09:24
  • 2
    Do we need that noise? Can't you just `docker-compose up web` and only show output from one service? `FROM alpine:3 COPY target/release/actixblog /app` Have you _compiled you application_ on alpine or with musl C standard library? What is the output of `type actixblog`? What is actixblog - a binary, python script? If it's a binary, how was it compiled / produced? Do you understand the difference between alpine and other distributions? Does https://stackoverflow.com/questions/66963068/docker-alpine-executable-binary-not-found-even-if-in-path answer your question? – KamilCuk Sep 28 '22 at 09:26
  • I've done something and it gives this error right now: `Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use`. Let me troubleshoot it further, then inform you. Most likely I will change the base image from Alpine to something else. – Eray Erdin Sep 28 '22 at 09:35
  • I know this doesn't answer the question but I have changed the base image to `fedora:36` and it worked. I will still keep the question open because someone might provide how they solved it with Alpine. – Eray Erdin Sep 28 '22 at 09:46

0 Answers0