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