When using my Rust App contanerized, the block_on
function from tokio::runtime
crashes:
Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.
I want to mention that this issue doesn’t happen when my app runs outside of a container.
I tried to run my app containerized with Docker, find docker-compose.yml
and Dockerfile
below.
version: '3.9'
services:
pg_index_db:
image: postgres
restart: always
shm_size: 512mb
environment:
POSTGRES_PASSWORD: default_password
POSTGRES_USERNAME: postgres
volumes:
- db_data:/var/lib/postgresql/data
ports:
- 5432:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 30s
timeout: 10s
retries: 5
deploy:
resources:
limits:
memory: 8gb
cpus: 4.0
joogle:
build: .
command: ["/usr/local/bin/joogle"]
ports:
- 8000:8000
deploy:
resources:
limits:
memory: 12gb
cpus: 4.0
volumes:
db_data:
driver: local
# BUILD CONFIG
FROM rustlang/rust:nightly
WORKDIR /joogle
COPY . .
RUN rustup component add rustfmt
RUN cargo build
# RUNTIME CONFIG
FROM debian:latest
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install --yes libcurl4
RUN DEBIAN_FRONTEND=noninteractive apt-get install --yes libc-bin
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=0 /joogle/target/debug/joogle /usr/local/bin/joogle
COPY --from=0 /joogle/static /usr/local/share/joogle/static
CMD ["joogle"]
EXPOSE 8000