2

Goal

Action: Run command from my local machine

Result: Docker image deployed on cloud instance

Approach

For remote deployment, I am using gcloud commands.

The command below is working but the only problem is that it is not picking environment variables file i.e. .env. I have this .env file placed in the working directory.

Command:

gcloud beta compute ssh --quiet --zone "us-west1-b" "devop-beta-persistent-2" --project "my-project" --command 'sudo docker run -p 8080:8080 -p 8443:8443 -p 50000:50000 -v ~/jenkins_data:/var/jenkins_home -v $FILE_PATH/jenkins.yaml:/var/configurations/jenkins_casc.yml --name jenkins-devkit --env-file $PWD/.env $JENKINS_IMAGE:latest'

Error: docker: open /.env: no such file or directory.

What I already tried

I have tried setting path to:

  • .env
  • /full/path/to/.env
  • $PWD/.env

but still getting the same error.

If I run this command on my local machine, it works fine i.e. picking up the .env file.

sudo docker run -p 8080:8080 -p 8443:8443 -p 50000:50000 -v ~/jenkins_data:/var/jenkins_home -v $FILES_PATH/jenkins.yaml:/var/configurations/jenkins_casc.yml --name jenkins-devkit --env-file $PWD/.env $JENKINS_IMAGE:latest

Can any one suggest the possible solution?

Faisal Umer
  • 31
  • 1
  • 5
  • Your `$PWD` will be resolving to the PWD on your host and not inside your container. That is why it is not working. Use the container path to `.env` file – Tarun Lalwani Dec 14 '20 at 15:48
  • The file is placed on my host machine and i have tried opening file using "vi $PWD/.env" and I can access it. Aren't we supposed to give the path of .env with respect to host? – Faisal Umer Dec 14 '20 at 15:55
  • 1
    That you will have to share inside the container using `-v` like you did for `jenkins.yaml` – Tarun Lalwani Dec 14 '20 at 17:04

1 Answers1

0

touch .env.dev fixed this error for me. touch is a unix command line program that creates a file. In my case .env.dev was missing. I created the file using touch. I created the file in the folder where I run my docker file.

Osvald Laurits
  • 1,228
  • 2
  • 17
  • 32