$(pwd) – one level up

I’m pretty new to the bash/shell script world, I’m trying to do the below and it could be pretty simple but I wasn’t able to figure out the command, would be great if someone could help me out here and also point me to some documentation wrt to shell script topics. Thank you in advance.

My build.sh and Dockerfile resides under a folder called .settings and this folder lives directly under the app root. Now inside my build.sh and Dockerfile when I refer something like $(pwd) or COPY . /apps/ it might not work since my build.sh and Dockerfile does not live directly under the app root.

  • Spring Boot can't read application.properties in Docker
  • Docker watchtower with private registry
  • Nvidia-docker - cant find libnvcuvid.so on building process
  • Ansible - playbook dynamic verbosity
  • How do I define the name of image built with docker-compose
  • Docker can't mount folder on windows
  • What command I can use in this scenario inside the files that I referenced above. Hope I made it clear. Once again this could be very simple since I’m a newbie in this arena I find it a little difficult.

    inside build.sh, reference to $(pwd)
    
    docker run \
    -u root \
    --rm \
    -v $(pwd):/app \ ----> this $(pwd) references the application root, but if I 
    move this build.sh inside a folder called .settings then the $(pwd) context 
    would change and I still want to refer it to the root.
    <MYIMAGE NAME FROM LOCAL REPO>
    

  • Should I include my webapp source in my docker image, or mount it when i run a container?
  • How to push only specific change in docker image
  • How can I make multiple copies of a docker container WITH configuration data?
  • How to save node-red console logs into a separate log file within docker
  • Docker swarm with NGINX proxy and websockets
  • How to connect Emacs' Elpy in-buffer python interpreter to docker container?
  • One Solution collect form web for “$(pwd) – one level up”

    The last arg to docker build, often something like docker build . is the build context in docker. This directory is sent to the server where the build runs and all COPY and ADD commands are performed using this context. These commands do not run on the client, and docker is a client/server application, so anything not in that context simply doesn’t exist for the purpose of building an image.

    So in the above example, docker build . the current directory is the build context and if that’s run while you’re inside of the .settings directory, only those files are part of the build context. Therefore your build.sh script needs to pass a different directory, and also reference where the Dockerfile is inside of that build context. That would look like:

    docker build -f .settings/Dockerfile ..
    

    When you do this, all of the COPY and ADD commands will now be relevant to parent directory, so you may need to adjust your Dockerfile to compensate.


    For your $(pwd) reference, you can either cd .. before running your docker run command or update the command to look like:

    docker run \
      -u root \
      --rm \
      -v $(pwd)/..:/app \
      <your image>
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.