Category Archives: Misc - Page 4

My Docker Cheat Sheet

Run a new container

docker run <container id or name>

Start a stopped container

docker start <container id or name>

Stop a container

docker stop <container id or name>

Kill a container

docker kill <container id or name>

Restart a container

docker restart <container id or name>

List all running containers

docker ps

List all containers

docker ps -a

List with formatted output (here only show name and status of containers)

docker ps --format '{{.Names}} {{.Status}}'

Inspect a container

docker inspect <container id or name>

List all ports a container uses

docker container port <container id or name>

Open Bash in container (‘exit’ to close)

docker exec -it <container id or name> bash

Watch STDOUT from container (‘-f’ for continued logging)

docker logs <container id or name>

Search containers in registry (example: “MySQL” gives all available MYSQL-containers)

docker search <search word>

Pull container from registry

docker pull <name>

Git: Rename “master” to “main”

More and more places are starting to rename their “master” branch to “main”. Here is a short description on one way to do that

1. We start with pulling/commiting all our work so that our Git tree is clean

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

2. Now we rename our local branch

niklas@HOME MINGW64 /c/git/my-project (master)
$ git branch -m master main

niklas@HOME MINGW64 /c/git/my-project (main)

3. Now we create the “main” branch on our remote

$ git push -u origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for main, visit:
remote:   https://git.mycompany.com/nb1-team/my-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=main
remote:
To https://git.mycompany.com/nb1-team/my-project.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

4. and lastly we remove the “master” branch to prevent any misstakes commiting to it in the future

$ git push origin --delete master
To https://git.mycompany.com/nb1-team/my-project.git
 - [deleted]         master

NOTE! If you have pipeline scripts that depended on “master” before you need to update them to use “main” now
NOTE 2! If your project used “master” as “Default branch” you need to change that to “main” now

Tested on Windows 10 and GitBash v3.5.2

How to use SPNEGO negotiation with Curl

1. First we need to check that we have an SPNEGO compatible Curl installed:

$ curl -V
curl 7.81.0 (x86_64-w64-mingw32) libcurl/7.81.0 OpenSSL/1.1.1m (Schannel) zlib/1.2.11 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.1 libssh2/1.10.0 nghttp2/1.46.0
Release-Date: 2022-01-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP zstd

Here we can see that the SPNEGO feature is available

2. Next we need to create a credentials cache for Curl to use

kinit <username>
Password for <username>@<domain.com>: <password>

Here we create a “authentication token” and put it in a credentials cache för Curl, and any other program ie. SoapUI and others, to use. ‘username’ is the name of the user. This can be omitted, and if so the default user and domain (user that runs the command) will be used instead. The ‘kinit’ command will ask for the password associated with the user. After this has been inputed the token is created

3. After that we run Curl with the following options:

curl --negotiate -u : https://a-spnego-protected-site/data-i-want-to-access

–negotiate will trigger SPNEGO behaviour
-u is needed but is left blank. On some sites though I have had to put <domain\user> to get it to work
: should point to the SPNEGO protected resource we want to access
Curl will now use the token in the credentials cache to authenticate against the web resource

Troubleshooting commands:

klist - lists all current tokens with the expiry timestamps in the cache
kdestroy - remove a ticket from the credentials cache

Tested with Curl v7.81.0 in GitBash on a Windows 10 with Java 1.8.0_301