Are arguments declared with ARG not available after the COPY command? I keep receiving the error : 'Split-Path : Cannot bind argument to parameter 'Path' because it is null.'
ARG arg_apgs_archive
COPY [ "$arg_apgs_archive", "/" ]
RUN powershell -Command "mkdir apgs; Expand-Archive -Path $(Split-Path $arg_apgs_archive -leaf) -DestinationPath '/APGS'"
ARG arg_generator_template_archive
COPY [ "$arg_generator_template_archive", "/" ]
RUN powershell -Command "mkdir temp/Jobs; Expand-Archive -Path $(Split-Path $arg_generator_template_archive -leaf) -DestinationPath '/temp/Jobs'"
Here are my build arguments:
'--build-arg BuildNumber=$(Build.BuildNumber) --build-arg arg_apgs_archive=drop/$(Build.BuildId)_APGS_Service.zip --build-arg arg_generator_template_archive=drop/gen-prod.zip'
Thanks
It appears to me that the ARGs are not available within the RUN commnds. Therefore the reason for the null within the Expand-Archive Path parameter.
Copying the ARG value to and ENV value allowed me to use the value in the powershell command.
ARG arg_apgs_archive
ENV apgs_archive = $arg_apgs_archive
COPY [ "$arg_apgs_archive", "/" ]
RUN powershell -Command "mkdir apgs; Expand-Archive -Path $(Split-Path $env:apgs_archive -leaf) -DestinationPath '/APGS'"
Related
For my projects I sometimes need to unittest my code against a ms sql server.
At the moment, I created a monstrous docker image, containing all the tools I need, including the sql server.
Now this image got to about 15 GB in size, which is really not cool.
So I'm trying to use the GitLab CICD Service part (as described here https://docs.gitlab.com/ee/ci/services/index.html).
But when I'm trying to add my (custom) image as a service I keep getting the health check issue:
*** WARNING: Service runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.lcaol__windowsdockerimages__mssql-0 probably didn't start properly.
Health check error:
service "runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.local__windowsdockerimages__mssql-0-wait-for-service" health check: exit code 1
Health check container logs:
2023-01-19T09:58:09.913696500Z FATAL: No HOST or PORT found
Service container logs:
*********
Now I found something online about needing to expose the ports of the service in the Dockerfile, so I tried that, but that did not help.
This is what my MSSQL DockerFile currently looks like:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Download Links:
ENV exe "https://go.microsoft.com/fwlink/?linkid=840945"
ENV box "https://go.microsoft.com/fwlink/?linkid=840944"
ENV sa_password="_" \
attach_dbs="[]" \
ACCEPT_EULA="Y" \
sa_password_path="C:\ProgramData\Docker\secrets\sa-password"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# make install files accessible
COPY start.ps1 /
WORKDIR /
RUN Invoke-WebRequest -Uri $env:box -OutFile SQL.box ; \
Invoke-WebRequest -Uri $env:exe -OutFile SQL.exe ; \
Start-Process -Wait -FilePath .\SQL.exe -ArgumentList /qs, /x:setup ; \
.\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS ; \
Remove-Item -Recurse -Force SQL.exe, SQL.box, setup
RUN stop-service MSSQLSERVER ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\' -name LoginMode -value 2 ;
HEALTHCHECK CMD [ "sqlcmd", "-Q", "select 1" ]
EXPOSE 1433/tcp
EXPOSE 4022/tcp
EXPOSE 135/tcp
EXPOSE 1434/tcp
EXPOSE 1434/udp
CMD .\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \"$env:attach_dbs\" -Verbose
And this is is my .gitlab-ci.yml file:
default:
image:
name: gitlab.mydomain.local:4567/windowsdockerimages/basicnetframeworkimage:latest
tags:
- windows
- docker
# The stages during this build
stages:
- build
build:
stage: build
script:
- echo "Hello world"
- ping mssql
- dotnet run
services:
- name: gitlab.mydomain.local:4567/windowsdockerimages/mssql
alias: mssql
Anyone who can help me get closer to the solution?
*Note, the ping mssql also fails, the container in which we run cannot find the DNS
entry
I would use an existing official image for MSSQL server (https://hub.docker.com/_/microsoft-mssql-server) and run unit tests in one container and the database in another one.
Good morning.
I am working with Docker for Windows 19.03.8, build afacb8b; running on Windows Server 2019 (10.0.17763.1039)
when I run Docker-Compose up -dV it says something like:
Creating network "docker_default" with the default driver
Creating docker_python-base_1 ... done
Creating docker_msbuild_1 ... done
but when I then use Docker-Compose exec, it says:
ERROR: No container found for msbuild_1
in other words, the UP and the EXEC are not using the same (default?) container name.
Al-waleed Shihadeh asked for more info (thanks you !!!!). so....
my docker-compose.yml file:
version: '3.7'
services:
python-base-srv:
build:
context: ./images/python-base
dockerfile: Dockerfile-PythonBase
image: mycompany/builds-win-base-python:3.7.6
volumes:
- ../../..:C:/bldroot
command: powershell -NoExit -NonInteractive
msbuild-srv:
build:
context: ./images/msbuild
dockerfile: Dockerfile-msbuild
image: mycompany/builds-win-msbuild:15.0
volumes:
- ../../..:C:/bldroot
depends_on:
- python-base-srv
command: powershell -NoExit -NonInteractive
Dockerfile-msbuild:
# escape=`
ARG FROM_IMAGE=mycompany/builds-win-base-python
FROM ${FROM_IMAGE} AS build
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN Invoke-WebRequest 'https://aka.ms/vs/15/release/vs_buildtools.exe' -OutFile C:\Downloads\vs_buildtools.exe -UseBasicParsing ; `
Start-Process -FilePath 'C:\Downloads\vs_buildtools.exe' -Wait `
-ArgumentList `
'--quiet', `
'--norestart', `
'--locale en-US', `
'--installPath C:\BuildTools', `
'--nocache', `
'--addProductLang en-US', `
'--add Microsoft.Net.Component.3.5.DeveloperTools', `
'--add Microsoft.Net.Component.4.5.TargetingPack', `
'--add Microsoft.Net.ComponentGroup.4.6.1.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.TargetingPacks.Common', `
'--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP' ; `
Remove-Item c:\Downloads\vs_buildtools.exe -Force
RUN $PATH = $env:PATH + ';C:\BuildTools\MSBuild\15.0\Bin' ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH
# Start developer command prompt before running the specified command (from RUN/EXEC commandline)
COPY ["VsDevCmdPowerShell.bat", "C:\\BuildTools\\"]
ENTRYPOINT ["cmd", "/k", "C:\\BuildTools\\VsDevCmdPowerShell.bat"]
Dockerfile-PythonBase:
# escape=`
ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019
FROM ${FROM_IMAGE} AS python-base
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN `
New-Item -Path C:\Downloads -ItemType Directory ; `
New-Item -Path C:\path -ItemType Directory ; `
`
$PATH = 'C:\path;' + $env:PATH ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH ; `
`
Invoke-WebRequest 'https://www.python.org/ftp/python/3.7.6/python-3.7.6.exe' -OutFile c:\Downloads\python-installer.exe -UseBasicParsing ; `
Start-Process c:\Downloads\python-installer.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; `
Remove-Item c:\Downloads\python-installer.exe -Force
CMD ["powershell", "-NoExit", "-NoLogo", "cmd", "/c ver", ";", "python", "--version", ";", "nuget", "help | select -First 1", ";"]
Outputs:
C:\work\docker> docker-compose up -dV msbuild-srv
Recreating docker_python-base-srv_1 ... done
Recreating docker_msbuild-srv_1 ... done
C:\work\docker> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------
docker_msbuild-srv_1 cmd /k C:\BuildTools\VsDev ... Exit 0
docker_python-base-srv_1 powershell -NoExit -NonInt ... Exit 0
C:\work\docker> docker logs docker_msbuild-srv_1
Call VsDevCmd.bat to setup environment . . .
C:\>call C:\BuildTools\Common7\Tools\VsDevCmd.bat
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
powershell -NoExit -NonInteractive
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\>
C:\>
C:\work\docker>
so - it is not leaving the containers running in the compose UP step like it should.
docker run -it works fine:
docker container run -it --name msbuildTesting -v C:/work:C:/bldroot -w c:\bldroot\build mycompany/builds-win-msbuild
it seems that your containers are exiting directly after docker-compose up, you can verify this by issuing these commands
docker-compose ps
or
docker ps -a
you also can check the reason why the containers exited by checking the logs
docker logs ${container_name}
Notes:
1. You should use this command to connect to the container docker-compose exec msbuild ${command}
I have to say that I'm new to Docker and Dockerfiles... I need to create a build that has a nano server and java installed.
I've created the following docker file, but I got the error below
Here's the file
# Installer image
FROM mcr.microsoft.com/windows/servercore:1909 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;`
Expand-Archive java.zip -DestinationPath java; `
And the error is
Error response from daemon: Dockerfile parse error line 8: unknown instruction: EXPAND-ARCHIVE
What am I doing wrong? I'm on a Windows Container runtime
Thanks
Microsoft's documentation now mention to use the \ to escape over multiple lines
RUN Write-Host "pwsh .bak copied across"; \
Get-ChildItem -Path /var/opt/mssql/backup \
Invoke-Sqlcmd -query "SELECT GETDATE() AS TimeOfQuery" \
Invoke-Sqlcmd -query "SELECT * from sys.databases" \
https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile#escape-character
Changed it to the following and tested. the error is gone.
# Installer image
FROM mcr.microsoft.com/windows/servercore:10.0.14300.1030 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';
$ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;
CMD [ "Expand-Archive", "java.zip", "-DestinationPath java;" ]
If I use env var "TEMP_DIR" in the file path like below:
"RUN $env:TEMP_DIR\BuildTools2017\vs_buildtools_2017.exe..."
or
"RUN $TEMP_DIR\BuildTools2017\vs_buildtools_2017.exe..."
Then, building will run into error:
"The system cannot find the path specified."
Why? How should I avoid using the hardcoded "C:\temp" in the file path, thanks.
Dockerfile to install the build tools for VS 2017:
FROM openjdk:8-jdk-windowsservercore
ARG version
ENV TEMP_DIR="c:/temp"
SHELL ["powershell","-NoProfile","-Command","$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]
# Create temp file for installers
RUN New-Item -ItemType Directory -Force -Path $env:TEMP_DIR;
# Install Visual Studio ultimate 2012
COPY ./VS2012_ultimate "c:/temp/VS2012_ultimate"
RUN \
Start-Process -FilePath "$env:TEMP_DIR/VS2012_ultimate/vs_ultimate.exe" - ArgumentList '/passive', '/q', '/s', '/norestart', '/noweb', '/full', -PassThru | Wait-Process;
# Install Blend.Sdk.WPF 4.0 & 4.5
COPY ./BlendSdk "$TEMP_DIR/BlendSdk"
RUN \
Start-Process -FilePath "$env:TEMP_DIR/BlendSdk/BlendWPFSDK_en.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process; \
Start-Process -FilePath "$env:TEMP_DIR/BlendSdk/BlendWPFSDK.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process;
# Install build tool for VS 2017
SHELL ["cmd", "/S", "/C"]
COPY ./BuildTools2017 "$TEMP_DIR/BuildTools2017"
RUN C:\temp\BuildTools2017\vs_buildtools_2017.exe --quiet --wait --norestart --nocache --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.VCTools
--add Microsoft.Net.Component.3.5.DeveloperTools --add Microsoft.VisualStudio.Component.Windows10SDK.17763
SHELL ["powershell", "-NoProfile", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; "]
Windows exposes %TEMP% environment variable:
RUN %TEMP%\BuildTools2017\vs_buildtools_2017.exe --quiet --wait --norestart --nocache --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.VCTools
Iam trying to pass a variable from jenkinsfile to a dockerfile. So i run a docker run command inside the jenkinsfile :
steps {
checkout scm
sh '''
echo ${GIT_BRANCH}
mkdir -p `pwd`/build_target
docker build -t android_build -f docker/Dockerfile.android .
docker run --env GIT_BRANCH=${GIT_BRANCH} android_build
ls -la `pwd`/build_target/*
'''
And try to use the env variable inside the dockerfile:
FROM openjdk:8u212-jdk
USER root
ENV GIT_BRANCH $GIT_BRANCH
RUN echo ${GIT_BRANCH}
RUN if [ "GIT_BRANCH" = "develop" ] ; then echo 'develop' ; else if [ "GIT_BRANCH" = "master" ] ; then echo 'aster' ; fi
But unfortunately it doesn't work and make the pipeline crashes as it can't get the env var.
What is wrong with my code ???
I ended by fixing the variable at build time with "--build-arg" flag, then i was able to use it inside the dockerfile. Hope it helps someone someday