Run Docker through Xcode XCTestCase - swift

I'm setting up tests for my Xcode Multiplatform App. To create a test environment I created a docker image that I want to run an XCTestCase against. I understand I'd have to make sure Docker is running before running the test. That said I'm having problems getting docker to build (run or kill).
I'm using a makefile to store the commands and planned to run the docker build and docker run commands in the setUpWithError while running the docker kill command in tearDownWithError. To run the commands I used Process to execute the shell commands. This works with ls but when I run the docker command I'm told docker: No such file or directory. Through ls I know I'm in the right location where the files exist. When switching to the terminal it works.
Is there something blocking docker from being run from my XCTestCase? If so is there anyway to get this to work or do I need to manually start docker and the docker container before running these tests?
Update
Got Docker running as it was a pathway issue. Rather than saying docker build... I now give it the entire path so /usr/local/bin/docker build.... New issue is that Xcode doesn't give me the permission to run this. I get:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create?name=remarkable": dial unix /var/run/docker.sock: connect: operation not permitted.
See 'docker run --help'.
Is there a way to allow me to run this in ONLY this XCTestCase?

Related

Keep containers running after build

We are using the Docker Compose TeamCity build runner and would like the containers to continue running after the build.
I understand that the docker-compose build step itself follows a successful 'up' with a 'down', so I have attempted to bring them back up in a subsequent command line step with simply:
docker-compose up -d
I can see from the log that this is initially successful but when the build process exits, so do the containers. I have also tried:
nohup docker-compose up -d &
The outcome is the same.
How do we keep the containers running when the build has finished?
For info, the environment is both TeamCity and its BuildAgent running on the same Ubuntu box.
I have achieved this by NOT using the Docker Compose build runner. I now just have a single command line build step doing:
docker-compose down
docker-compose up -d
This works, and I feel rather silly ;-)

MongoDB init script doesn't run on Docker run by Jenkins SSH agent

I have a Docker container with MongoDB, with a /docker-entrypoint-initdb.d/... script with my initial mongo config.
The problem is that it doesn't get executed when run by Jenkins (through docker-compose up via SSH). When I start the container "manually" (same command through console, also SSH) - all is fine.
I'm a newbie at Jenkins, I think that's the case - the Jenkins SSH agent ceates a workspace that differs from the dir that Docker uses when run by me through terminal. But all the required files are there.. maybe it has sth to do with the script being executed only on initial startup? I tried removing it from the agent's workspace to be initialized again, but still no luck..

Podman isn't working in Remote Containers in Windows?

Any hints on why Remote - Containers isn't working with podman on Windows?
Installed podman v4.2.0 on Windows 11 via .msi package
Set remote.containers.dockerPath to podman in VS Code Settings
Run podman machine init
Run podman machine start
Open Remote Explorer in VS Code and be presented with the following:
Everything is working with podman — pull, run, images, etc, but Remote - Containers on VSCode doesn't recognize podman.
After running Remote-Containers Developer: Show All Logs... in VS Code:
[2022-08-21T12:55:15.916Z] Start: Run: podman version --format {{.Server.APIVersion}}
[2022-08-21T12:55:16.080Z] Stop (164 ms): Run: podman version --format {{.Server.APIVersion}}
[2022-08-21T12:55:16.080Z] Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman. failed to create sshClient: dial unix \\.\pipe\openssh-ssh-agent: connect: No connection could be made because the target machine actively refused it.
And podman system connection list in a terminal:
Name URI Identity Default
podman-machine-default ssh://user#localhost:62078/run/user/1000/podman/podman.sock C:\Users\Edmundo\.ssh\podman-machine-default true
podman-machine-default-root ssh://root#localhost:62078/run/podman/podman.sock C:\Users\Edmundo\.ssh\podman-machine-default false
Related Issues: #6957, #6747.
Please confirm you are running the latest build (prerelease)
v0.236.1.
(there are known issues on github with earlier release, fixed in this version)
in a WSL shell, i.e. for debugging try this
first - try to start podman podlib REST api (for socket, lifetime 5000 sec. - set to zero for "forever")
podman system service -t 5000 &
then symlink the podman.sock to the location vscode expects:
sudo ln -s /mnt/wslg/runtime-dir/podman/podman.sock /var/run/docker.sock
if none of that works, would you mind posting a dump:
podman info
HINT: check the podman info YAML output for host | remoteSocket | path & make sure it matches the path /mnt/wslg/runtime-dir/podman/podman.sock above.
The bug being tracked on GitHub. One step you should also do is enable Run in WSL in VS Code Development Container extension settings. Then it will run the podman commands in the podman-machine-default wsl instance.

docker-compose portmapping gives failed to create endpoint hnsCall failed in Win32: The specified port already exists

I have started a new (.net core 3.0)project in Visual Studio, with Docker support (Windows)
I have added Docker support (right-click on project Add->Docker support) and in the same way added Docker compose support.
If I just Click "play-button" for Docker Compose, the project starts everything works well.
But when I run docker-compose up from the solution folder I get
Cannot start service testproj30: failed to create endpoint
testproj30_testproj30_1 on network nat: hnsCall failed in Win32: The
specified port already exists.
(I have closed my VS solution). If I remove the port mapping in docker-compose.override.yaml I dont get this error message. I have dont the most common tricks with restarting docker servce, hni service and so on. Nothing helps.
I dont want to depend on all VS-voodoo from the project file and God knows what other files that are involved.
I can run docker run -p 8080:80 443:443 without any port problems
I fixed a similar problem by removing some terminated container and then pruning networks.
List terminated container :
docker ps -a
Remove them (Cygwin syntax) :
docker rm $(docker ps -aq)
You will have error message for runnnig containers.
Clean your networks :
docker network prune
For myself, the main cause was the Docker killing process skiped the port releasing mechanism of my application.

Windows console giving error when run as Container via docker RUN command

I created a Windows console app and in that console app I added Docker Orchestration support using "Docker Compose". When I run it by clicking on Docker Compose, it runs successfully
See in below image screenshot it shows I have added Docker file, I also have Docker Compose project. You can also see I have run by clicking "Docker Compose".
Now when I run it using Docker command as below
docker run -it consoleappcontainer:dev
It throws below error
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: container aedbd4bd0f60eb0184cce3570be103d121c516eac3cf222662258f6dd0ca0c50 encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(174)\vmcomputeagent.exe!00007FF7303DC00A: (caller: 00007FF7303AECEA) Exception(2) tid(380) 80070002 The system cannot find the file specified.
CallContext:[\Bridge_ProcessMessage\ComputeSystemManager_ExecuteProcess\VmHostedContainer_ExecuteProcess]
Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"C:\\app\\ConsoleAppContainer.exe","WorkingDirectory":"C:\\app","Environment":{"COMPLUS_NGenProtectedProcess_FeatureEnabled":"0"},"EmulateConsole":true,"CreateStdInPipe":true,"CreateStdOutPipe":true,"ConsoleSize":[50,192]}.
See error screenshot
Below is my DOCKER file
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["C:\\app\\ConsoleAppContainer.exe"]
Why can't it find the EXE when it ran correctly using DOCKER COMPOSE button?
I don't know exactly what Visual Studio does when you run from there... see if there's something in the Output Window that could give you a hint...
One more thing, when docker compose is involved you should start it with docker-compose up. The docker-compose.yml file must have something that you're missing when you want to just start the container with docker run