0

I'm new to Docker and recently attempted to set up Apache Airflow within a Docker container following some online tutorials. Here's a breakdown of the steps I've taken: I ran a Docker container using the command:docker run -it --rm -p 8888:8080 python:3.8-slim /bin/bash I created a separate path for Apache Airflow using:export AIRFLOW_HOME=/opt/airflow I added a user named "airflow" using:useradd -ms /bin/bash -d ${AIRFLOW_HOME} airflow I navigated to the path and created a virtual environment for Apache Airflow:su - airflow cd /opt/airflow python -m venv .airflowvirtualenv source .airflowvirtualenv/bin/activate However, upon restarting my machine, I encountered an issue. The Docker GUI showed the container and its associated image file, and I could access the container's root user. But when I tried to access the "airflow" user and its virtual environment, I received a "User does not exist" error.

My goal was to retain the user setup and virtual environment and installed airflow python across container restarts. I'm not sure how to effectively persist these changes within Docker containers, and I'd appreciate guidance on how to accomplish this.

Could anyone provide insights into how I can retain user setups and virtual environments in Docker containers to use Apache Airflow consistently across restarts?

However, the issue arose when I restarted my machine. While the Docker GUI displayed the container and associated image file, I was only able to access the container's root user. Attempting to access the "airflow" user and its virtual environment resulted in a "User does not exist" error.

  • --rm flag deletes the container once the iteractive (-it) finished (restart, close terminal and more). how do you access it ? are you sure its the same container id (unlikely) – ozs Aug 23 '23 at 15:37
  • No,It was different container ID with some random name . But It erased all after restart . So suggest me how can i retain all config forever?? – Nabaraj Ghimire Aug 23 '23 at 16:26
  • remove the --rm and then the container exsit until manually delete it – ozs Aug 23 '23 at 16:54

1 Answers1

0

When you add --rm then the container will be deleted once the iteractive ends.

  • remove the --rm in order to keep your container
  • you can also add --restart unless-stopped so in case of computer restart the container automaticly will start once the docker service starts.

docker run -it --restart unless-stopped -p 8888:8080 python:3.8-slim

ozs
  • 3,051
  • 1
  • 10
  • 19