last day (15 days later) » 

11:55
0
A: Run script in Dockerfile to add aliases

ShubhamEdit: I stripped the docker-compose.yml file to below as I do not have the dependencies: version: '3.1' services: laravel: container_name: laravel build: . ports: - 8445:443 volumes: - .:/app environment: docker: 'true' WEB_DOCUMENT_ROOT: '/app/pub...

Ok, you're not missing anything, but I'm probably missing something from my question. I'm using docker-compose - I think that might be the difference.
It shouldn't create a difference. docker-compose.yml should work in the same way as docker run .... Please provide the docker-compose.yml file too in the question anyway to make it easier to debug.
After running docker-compose up -d, if you run docker-exec -it laravel cat /root/.bashrc, do you still see the new alias?
@GluePear yes. I still see the new alias. Also, -d only detaches the container from the tty and should have no effect in this situation.
Ok - then I am puzzled. You are using the exact same Dockerfile, docker-bootstrap.sh, and almost exactly the same docker-compose.yml file. Thank you for your time on this.
11:55
@GluePear Hold on, you mean docker exec ... or docker-exec ... ?
No, sorry, docker exec
Hmm.
that's really strange.
Even I am intrigued now. What can be causing this issue?
you are root when you exec in the container, right?
can you build the container again? Did you provide executable permissions to the .sh file ?
So my entire process is:

docker-compose down -v
docker build --no-cache=true . // Just to be sure I build it again each time
docker-compose up -d
docker exec -it laravel /bin/bash
cat /root/.bashrc
I have also (since asking my question) added executable permissions to the file:

FROM webdevops/php-apache-dev:7.2
ADD docker-bootstrap.sh /docker-bootstrap.sh
RUN chmod +x /docker-bootstrap.sh
RUN /docker-bootstrap.sh
can you exec in the container and then execute the /docker-bootstrap.sh file manually?
So, the process is to do this:

docker build -t --no-cache=true .
docker run -it <image> bash
and then execute the .sh file once you are connected to the container shell
(I get an error if I use the -t flag).
12:02
sorry, do not use the -t flag in docker build.
But the thing is, if I do this:

docker build --no-cache=true
docker run -it <image> cat /root/.bashrc

then I see the new alias!
But if I exec into the container with docker exec -it laravel /bin/bash, it's not there
woah!
seems unreal to me :D
hold on, lemme think
can you paste the current Dockerfile here.
so that I can do some things from my end
FROM webdevops/php-apache-dev:7.2
ADD docker-bootstrap.sh /docker-bootstrap.sh
RUN chmod +x /docker-bootstrap.sh
RUN /docker-bootstrap.sh
Hey, thanks for persisting with this. I have to check out for half an hour, back after that.
Hey, it doesn't matter for me if I run bash and then exec into the container or directly run cat command. I can see the alias at all times.
@GluePear cool
Ach then that is really strange. I have also tried restarting my Docker client.
12:08
can you paste the terminal activity ?
Oh but wait, the distinction I wanted to make was not between bashing into container or directly running cat command.
The distinction is this:
I mean when you run cat directly and when you exec and cat
I know, it's not that, one sec:
docker run -it e688ead87023 cat /root/.bashrc

shows the new alias

docker exec -it laravel cat /root/.bashrc

does not show the new alias
docker exec cannot run with a preceding docker run
docker exec works for me without run, it shows the default .bashrc file, just without the new alias
12:12
interesting
Can you stop all the containers and kill them and then try if you're able to directly docker exec without docker run or docker-compose up?
Because if all the container are stopped and I try `docker exec` without `docker run`, I get this:

docker exec -it laravel cat /root/.bashrc
Error response from daemon: Container d15a8ba50c8822a12c1782266446a95a1a17857e2a51fba7ead51fcab76ebd65 is not running
12:58
That's the same with me. I have to run docker-compose up first.
So I was not quite clear before when I said docker exec works for me without run. I meant without the explicit docker run command.
13:51
Did you try stopping and killing all the containers and then doing it again?
Also, can you post the terminal activity while you do it?
Ok, so:

`docker-compose down -v`

Output:

Stopping laravel ... done
Stopping src_phpmyadmin_1 ... done
Stopping src_phpmyadmin_test_1 ... done
Stopping src_laravelmysql_1 ... done
Stopping src_testmysql_1 ... done
Removing laravel ... done
Removing src_phpmyadmin_1 ... done
Removing src_phpmyadmin_test_1 ... done
Removing src_laravelmysql_1 ... done
Removing src_testmysql_1 ... done
Removing network src_default
Then:

`docker kill $(docker ps -q)`
Output:

"docker kill" requires at least 1 argument.
See 'docker kill --help'.
I guess because I've removed everything?
Now:

docker-compose up -d

Output:

Creating network "src_default" with the default driver
Creating src_laravelmysql_1 ... done
Creating src_testmysql_1 ... done
Creating src_phpmyadmin_test_1 ... done
Creating src_phpmyadmin_1 ... done
Creating laravel ... done
And:

docker exec -it laravel cat /root/.bashrc

Output:

Standard unmodified `.bashrc` file (without new alias)
14:06
Allow me some time. I am in transit. Will look in after 40 mins.
Thank you. I will keep working on it
14:20
Ok, I have found a solution. Instead of running docker-compose up -d, I need to run docker-compose up --build
Very simple... Thank you for your help on this. If you want to post that as an answer I will mark it correct.
14:45
I believe you can run docker-compose up -d --build and even that'll work.
-d and --build serve different purposes. -d is to run it in detached mode (detached to tty) and --build is to rebuild the container before starting it up.
So basically, the whole issue was that you build the image and then probably added the .sh file later on in the Dockerfile but did not rebuild the images with changes.
Once rebuild, the new changes (alias because of .sh) files were in effect?
Yes, I know -- sorry I forgot to add -d in the second example.
Yes, once rebuilt, the new changes were there after running docker-compose up -d --build
Cool. Turned out trivial :p
It did indeed :) Thanks again
You're welcome. :)
I'll add the rebuild part in my answer.
Cool
14:53
I have a relevant meme if you're interested :|
Sure!
hahaha yes story of my life
everyone's story :D
I would maybe modify your answer a bit (if you can be bothered - you've already spent a lot of time on this I know). For my the solution was specifically to run docker-compose up -d --build. I.e. it did not work for me to first run docker build . then to run docker-compose up -d. Instead I omitted the docker build . statement then ran docker-compose up -d --build.
15:05
No problem. Allow me to explain why this happened.
It didn't work for you when you run docker build . and then docker-compose up -d because when you don't use -t with docker build (as in docker build -t) the image created will be a random hex.
but since you're not referencing this new random image in your docker-compose.yml file, it didn't work.
Aha. That makes sense.
when you run docker-compose --build it'll build the image with the same name, i.e., the same image is modified.
Yes.
Actually, I remember I told you to skip -t when using docker build because we were just testing anyway. If you use docker build -t <image_name> . and then docker-compose up -d, things will work.
Yes I remember that.
Exactly.
Ok, thanks again! I think that means I can mark your answer as correct, since you do suggest rebuilding the image to be sure, and since the original question was not about this subject exactly (it was not about the details of specifying a name when building the docker image).
15:10
you're welcome and happy to help. yes, it was hard to think the the issue would turn out to be so trivial. :D

last day (15 days later) »