skip to Main Content

I have a dockerized php application. I want to set the version and the buildTime as a env variable from a file called version

VERSION=$(head -n 1 version) 

buildTime=$(head -2 version | tail -1)

The problem that it consider the dash in -n and -1 as a special characters.
How can I solve this problem?

2

Answers


  1. I’m going to imagine you have a file called version which ONLY contain the version of your system

    Why just don’t

    VERSION=$(cat version)
    

    If for some reason you have other information in this file, you can just use sed.

    VERSION=$(sed '1!d' version)
    
    Login or Signup to reply.
  2. Make use of –env-file option of docker run command.

    • Create version.env file containing the required details
    version=v1
    buildtime=01-01-2019
    
    • Specify the environment file in docker run command.
    docker run -itd --env-file=/path/to/version.env image:v1
    

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search