vscode-remote-container open user terminal after post*Command - docker

if you run a post*Command you get an integrated terminal that runs the command(s) and outputs:
Running the PostCreateCommand from devcontainer.json...
[2709 ms] Start: Run in container: ...
Done. Press any key to close the terminal.
is there a way to have this auto close and open a user terminal or just leave it and open a user terminal as if you werent running any commands from devcontainer.json at all?

Using an example involving Python, you can try using postAttachCommand:
{
"postCreateCommand": ["poetry", "install"],
"postAttachCommand": "bash"
}
which gives:
Running the postCreateCommand from devcontainer.json...
[28000 ms] Start: Run in container: poetry install
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: project (0.1.0)
Running the postAttachCommand from devcontainer.json...
[33815 ms] Start: Run in container: /bin/sh -c bash
root#a0fd27a3b2cc:/workspaces/directory#
The description for postCreateCommand reads:
A command to run after creating the container. This command is run after "updateContentCommand" and before "postStartCommand".
whereas the description for postAttachCommand specifies:
A command to run when attaching to the container. This command is run after "postStartCommand".
So other variations might be possible, but this one worked for me.

Related

Enable and Start Queue in Dockerfile

I need some help on how to configure Dockerfile so my queue works as expected. I already tried to run this manually inside container, so I need this to run Automatically after each deploy in gitlab. Here's what I did manually inside the container
sudo service supervisor enable
sudo service supervisor start
ps aux | grep artisan
It works perfectly, but with Dockefile, I need it to run those commands. Heres my excerpt of the Dockefile
COPY gal-worker /etc/supervisor/conf.d/gal-worker.conf
COPY gal-schedule /etc/supervisor/conf.d/gal-schedule.conf
RUN chown -R root:root /etc/supervisor/conf.d/*.conf
# Make sure Supervisor comes up after a reboot.
RUN sudo service supervisor enable
# Bring Supervisor up right now.
RUN sudo service supervisor start
But my pipeline cant succeed due to errors:
Step 33/34 : RUN sudo service supervisor enable
---> Running in c04c3ab807d2
Usage: /etc/init.d/supervisord {start|stop|restart|force-reload|status}
The command '/bin/sh -c sudo service supervisor enable' returned a non-zero code: 1
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
Any ideas ?

Is there any way to run "pkexec" from a docker container?

I am trying to set up a Docker image (my Dockerfile is available here, sorry for the french README: https://framagit.org/Gwendal/firefox-icedtea-docker) with an old version of Firefox and an old version of Java to run an old Java applet to start a VPN. My image does work and successfully allows me to start the Java applet in Firefox.
Unfortunately, the said applet then tries to run the following command in the container (I've simply removed the --config part from the command as it does not matter here):
INFO: launching '/usr/bin/pkexec sh -c /usr/sbin/openvpn --config ...'
Then the applet exits silently with an error. While investigating, I've tried running a command with pkexec with the same Docker image, and it gives me this result:
$ sudo docker-compose run firefox pkexec /firefox/firefox-sdk/bin/firefox-bin -new-instance
**
ERROR:pkexec.c:719:main: assertion failed: (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) > 0)
But I don't know polkit at all and cannot understand this error.
EDIT: A more minimal way to reproduce the problem is with this Dockerfile:
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install -y policykit-1
And then run:
$ sudo docker build -t pkexec-test .
$ sudo docker run pkexec-test pkexec echo Hello
Which leads here again to:
ERROR:pkexec.c:719:main: assertion failed: (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) > 0)
Should I conclude that pkexec cannot work in a docker container? Or is there any way to make this command work?
Sidenote: I have no control whatsoever on the Java applet that I try to run, it is a horrible and very dated proprietary black box that I am supposed to use at work, for which I have no access to the source code, and that I must use as is.
I have solved my own problem by replacing pkexec by sudo in the docker image, and by allowing passwordless sudo.
Given an ubuntu docker image where a user called developer was created and configured with a USER statement, add these lines:
# Install sudo and make 'developer' a passwordless sudoer
RUN apt-get install sudo
ADD ./developersudo /etc/sudoers.d/developersudo
# Replacing pkexec by sudo
RUN rm /usr/bin/pkexec
RUN ln -s /usr/bin/sudo /usr/bin/pkexec
with the file developersudo containing:
developer ALL=(ALL) NOPASSWD:ALL
This replaces any call to pkexec made in a process running in the container, by a call to sudo without any password prompt, which works nicely.

'bash' : no such file or directory

I just joined the windows insider program so I could install Ubuntu and install Ruby via bash commands. Everytime I open the the ubuntu command prompt it will not allow me to run any commands without throwing errors. examples
Command 'sudo' is not availiable in '/usr/bin/sudo'
At the top of the Ubuntu command prompt it says:
/usr/bin/env: 'bash': no such file or directory
How can I resolve this issue. I need to set up ruby so I can start developing.
You can check content of PATH variable by executing command $ echo $PATH
If you do not find /usr/bin in the output than you can append /usr/bin in PATH variable by executing command
$ export PATH=$PATH:/usr/bin

Unable to run pre-installation script /var/lib/dpkg/tmp.ci/preinst

I try to install some program in Docker, but get:
preinst /var/lib/dpkg/tmp.ci/preinst install
The requested cluster does not exist and cluster creation is not supported.
dpkg: error processing archive arch.deb (--install):
subprocess new pre-installation script returned error exit status 1
postrm /var/lib/dpkg/tmp.ci/postrm abort-install
The Docker container is created FROM ubuntu:14.04
The code I use in Dockerfile is:
RUN sudo ./dir/install.sh
This code works fine on Ubuntu 14.04 directly, but not in Docker. Any thoughts? Do I need to install/add something extra first?

initctl too old upstart check

I am trying to do a syntax check on an upstart script using init-checkconf. However when I run it, it returns ERROR: version of /sbin/initctl too old.
I have no idea what to do, I have tried reinstalling upstart but nothing changes. This is being run from within a docker container (ubuntu:14.04) which might have something to do with it.
I just ran into the same issue.
Looking in the container:
root#puppet-master:/# cat /sbin/initctl
#!/bin/sh
exit 0
I haven't tested it completly yet, but I added the following to my Dockerfile:
# Fix upstart
RUN rm -rf /sbin/initctl && ln -s /sbin/initctl.distrib /sbin/initctl
I thought this link explained it pretty good:
When your Docker container starts, only the CMD command is run. The only processes that will be running inside the container is the CMD command, and all processes that it spawns. That's why all kinds of important system services are not run automatically – you have to run them yourself.
Digging around some more, I found an official Ubuntu image containing a working version of upstart:
https://registry.hub.docker.com/_/ubuntu-upstart/

Resources