Skip to content

Commit 5f98a2a

Browse files
committed
adding best practices for docker images
1 parent 621123d commit 5f98a2a

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

pages/docs/user-docs/docs-docker.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ permalink: docs-docker
55
folder: docs
66
---
77

8+
{% include toc.html %}
9+
810
Singularity is good friends with Docker. The reason is because the developers use and really like using Docker, and scientists have already put much resources into creating Docker images. Thus, one of our early goals was to support Docker. What can you do?
911

1012
- You don't need Docker installed
@@ -166,7 +168,7 @@ Given the definition, the `ENTRYPOINT` is most appropriate for the Singularity `
166168

167169

168170

169-
# How do I specify my Docker image?
171+
## How do I specify my Docker image?
170172

171173
In the example above, you probably saw that we referened the docker image first with the uri `docker://` and that is important to tell Singularity that it will be pulling Docker layers. To ask for ubuntu, we asked for `docker://ubuntu`. This uri that we give to Singularity is going to be very important to choose the following Docker metadata items:
172174

@@ -199,11 +201,11 @@ If you want to change any of those fields, then just specify what you want in th
199201

200202

201203

202-
# Custom Authentication
204+
## Custom Authentication
203205
For both import and bootstrap using a build spec file, by default we use the Docker Registry `index.docker.io`. Singularity first tries the call without a token, and then asks for one with pull permissions if the request is defined. However, it may be the case that you want to provide a custom token for a private registry. You have two options. You can either provide a `Username` and `Password` in the build specification file (if stored locally and there is no need to share), or (in the case of doing an import or needing to secure the credentials) you can export these variables to environmental variables. We provide instructions for each of these cases:
204206

205207

206-
#### Authentication in the Singularity Build File
208+
### Authentication in the Singularity Build File
207209
You can simply specify your additional authentication parameters in the header with the labels `Username` and `Password`:
208210

209211
```bash
@@ -213,15 +215,15 @@ Password: [password]
213215

214216
Again, this can be in addition to specification of a custom registry with the `Registry` parameter.
215217

216-
#### Authentication in the Environment
218+
### Authentication in the Environment
217219
You can export your username, and password for Singularity as follows:
218220

219221
```bash
220222
export SINGULARITY_DOCKER_USERNAME=vanessasaur
221223
export SINGULARITY_DOCKER_PASSWORD=rawwwwwr
222224
```
223225

224-
##### Testing Authentication
226+
### Testing Authentication
225227
If you are having trouble, you can test your token by obtaining it on the command line and putting it into an environmental variable, `CREDENTIAL`:
226228

227229

@@ -238,6 +240,22 @@ http https://index.docker.io/v2/vanessa/code-samples/tags/list Authorization:"Be
238240

239241
The above call should return the tags list as expected. And of course you should change the repo name to be one that actually exists that you have credentials for.
240242

243+
## Best Practices
244+
While most docker images can import and run without a hitch, there are some special cases for which things can go wrong. Here is a general list of suggested practices, and if you discover a new one in your building ventures please <a href="https://www.github.com/singularityware/singularityware.github.io/issues" target="_blank">let us know</a>.
245+
246+
### 1. Installation to Root
247+
When using Docker, you typically run as root, meaning that root's home at `/root` is where things will install given a specification of home. This is fine when you stay in Docker, or if the content at `/root` doesn't need any kind of write access, but generally can lead to a lot of bugs because it is, after all, root's home. This leads us to best practice #1.
248+
249+
>> Don't install anything to root's home, `/root`.
250+
251+
### 2. Library Configurations
252+
The command [ldconfig](https://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/) is used to update the shared library cache. If you have software that requires symbolic linking of libraries and you do the installation without updating the cache, then the Singularity image (in read only) will likely give you an error that the library is not found. If you look in the image, the library will exist but the symbolic link will not. This leads us to best practice #2:
253+
254+
>> Update the library cache at the end of your Dockerfile with a call to ldconfig.
255+
256+
257+
Have any more best practices? Please <a href="https://www.github.com/singularityware/singularityware.github.io/issues" target="_blank">let us know</a>!
258+
241259

242260
## Troubleshooting
243261
Why won't my image bootstrap work? If you can't find an answer on this site, please <a href="https://www.github.com/singularityware/singularity/issues" target="_blank">ping us an issue</a>.

0 commit comments

Comments
 (0)