Three ways to copy and share data to a Docker container:
-
Providing data on build time: Docker ADD vs COPY
-
Providing data on run time: How to copy files to or from a Docker container
-
Sharing data via volumes: Using volumes in Docker Compose
Three ways to copy and share data to a Docker container:
Providing data on build time: Docker ADD vs COPY
Providing data on run time: How to copy files to or from a Docker container
Sharing data via volumes: Using volumes in Docker Compose
| version: '3' | |
| networks: | |
| test_net: | |
| services: | |
| webserver: | |
| image: nginx:alpine | |
| command: sh -c 'sleep 10 && nginx -g "daemon off;"' | |
| networks: | |
| - test_net |
| #!/usr/bin/env bash | |
| echo '{"cities": [{"name": "Barcelona"}, {"name": "Copenhagen"}, {"name": "Edinburgh"}, {"name": "Hanoi"}]}' > /tmp/cities.json | |
| docker run -d -p 80:80 -v /tmp/cities.json:/data/db.json clue/json-server | |
| # Listing my favourite cities | |
| curl http://localhost/cities | |
| [ | |
| {"name": "Barcelona"}, | |
| {"name": "Copenhagen"}, |
A user wants profile data from an app.
# run mongo
$ docker run --rm --name my-mongo -it -p 27017:27017 mongo:3.2.7
# or as a daemon
$ docker run --name my-mongo -d mongo:3.2.7
# connect to the previous container.. with another container
$ docker run -it --link my-mongo:mongo --rm mongo:3.2.7 sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'| require 'benchmark' | |
| require 'ostruct' | |
| Benchmark.bm 10 do |bench| | |
| bench.report "Hash: " do | |
| 10_000_000.times do { name: "John Doe", age: 32 } end | |
| end | |
| bench.report "Struct: " do | |
| Person = Struct.new(:name, :age) |
| # start vm | |
| vboxmanage startvm vm_name | |
| # stop vm | |
| vboxmanage controlvm vm_name poweroff | |
| # clone vm | |
| vboxmanage clonevm vm_name --name new_vm_name --register --mode all |
| ## | |
| # /etc/nginx/sites-available/my_site.conf | |
| # forces https | |
| server { | |
| listen 80; | |
| return 301 https://my_server$request_uri; | |
| } | |
| server { |
Display all envs vars
printenvSet $JAVA_HOME and $SCALA_HOME (Mac OS X)
export JAVA_HOME=$(/usr/libexec/java_home)
export SCALA_HOME=/usr/local/share/scala
export PATH=${PATH}:$JAVA_HOME/bin:$SCALA_HOME/bin