Skip to content

Instantly share code, notes, and snippets.

View indzi's full-sized avatar

Indranil SInha indzi

  • Crypto Currency Trading
  • Singapore
View GitHub Profile
# Docker Cheat Sheet
**Want to improve this cheat sheet? See the [Contributing](#contributing) section!**
## Table of Contents
* [Why Docker](#why-docker)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Containers](#containers)
#### Capabilities
Linux capabilities can be set by using `cap-add` and `cap-drop`. See <https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities> for details. This should be used for greater security.
To mount a FUSE based filesystem, you need to combine both --cap-add and --device:
```
docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs
```
#### Memory Constraints
You can also set [memory constraints](https://docs.docker.com/engine/reference/run/#/user-memory-constraints) on Docker:
```
docker run -it -m 300M ubuntu:14.04 /bin/bash
```
#### CPU Constraints
You can limit CPU, either using a percentage of all CPUs, or by using specific cores.
For example, you can tell the [`cpu-shares`](https://docs.docker.com/engine/reference/run/#/cpu-share-constraint) setting. The setting is a bit strange -- 1024 means 100% of the CPU, so if you want the container to take 50% of all CPU cores, you should specify 512. See <https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/#_cpu> for more:
```
docker run -it -c 512 agileek/cpuset-test
```
### Starting and Stopping
* [`docker start`](https://docs.docker.com/engine/reference/commandline/start) starts a container so it is running.
* [`docker stop`](https://docs.docker.com/engine/reference/commandline/stop) stops a running container.
* [`docker restart`](https://docs.docker.com/engine/reference/commandline/restart) stops and starts a container.
* [`docker pause`](https://docs.docker.com/engine/reference/commandline/pause/) pauses a running container, "freezing" it in place.
* [`docker unpause`](https://docs.docker.com/engine/reference/commandline/unpause/) will unpause a running container.
* [`docker wait`](https://docs.docker.com/engine/reference/commandline/wait) blocks until running container stops.
* [`docker kill`](https://docs.docker.com/engine/reference/commandline/kill) sends a SIGKILL to a running container.
* [`docker attach`](https://docs.docker.com/engine/reference/commandline/attach) will connect to a running container.
@indzi
indzi / TransientPropertyValueException
Created April 15, 2019 11:27
org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation : com.bitex.affiliation.core.entity.AffiliationUserEntity.profile -> com.bitex.affiliation.core.
//Try putting CascadeType.ALL
@OneToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
@JoinColumn(name="COUNTRY_ID", nullable=false)
private Country country;
@indzi
indzi / annotations
Last active July 6, 2018 07:27
List of common spring annotations
//Annotation to declare a class as a spring Bean
@Component
class Bean{
public String printDate(){
return "Now it is: "+LocalDateTime.now();
}
@PostConstruct
public void post(){
System.out.println("Output: "printDate());
@indzi
indzi / CP1.md
Created April 9, 2018 08:22 — forked from sharmaeklavya2/CP1.md
Getting started with Competitive Programming

Starting out with Competitive Programming

(This guide is meant for beginners. If you have solved 100+ problems and are looking for guidance on how to solve problems involving algorithms and data structures, this document is not for you.)

Competitive Programming is an interesting activity which mixes problem solving with programming. It is not only enjoyable but also very demanded in placements. Competitive programming will make you very good at writing efficient programs quickly.

@indzi
indzi / checkout
Last active February 27, 2018 10:15
create a working copy of a local repository by running the command
git clone /path/to/repository
when using a remote server, your command will be
git clone username@host:/path/to/repository
@indzi
indzi / attributeBinding
Last active February 6, 2018 07:55
Don’t forget: Polymer camel-cases properties, so if in JavaScript you use myProperty, in HTML you would use my-property.
<some-element hidden$="[[myProperty]]"></some-element>
Attribute binding: when myProperty is true, the element is hidden; when it’s false, the element is visible. The difference between attribute and property binding is that property binding is equivalent to someElement.someProp = value, whereas attribute binding is equivalent to: someElement.setAttribute(someProp, value)