Skip to main content

Posts

Showing posts from August, 2019

Why won't react re-render on state change?

If you mutate the state directly it won't re-render. Instead of... [cart, setCart] = useState([1,2,3]) const updateCart = (item) => {   prevCart = cart   prevCart.push(item)   setCart(prevCart) } Do this.... const updateCart = (item) => {   let prevCart = []   cart.forEach(item => {       prevCart.push(item)   });   setCart(prevCart) }

Backup dockerized mongodb

### Backup mongo db container on docker host ``` docker run --rm --network [network] --link [db_container]:mongo -v /Users/sam/db_backups:/backup mongo bash -c 'mongodump -u [username] -p [password] --out /backup --host mongo:27017' ``` ### Restore mongodb database ``` docker run --rm --network [network] --link [db_container]:mongo -v /Users/sam/db_backups:/backup mongo bash -c 'mongorestore -u [mong_username] -p [mong_password] /backup --host mongo:27017' ``` The restore will wipe everything that existed before-hand.

Attach existing volume to container with docker-compose

`docker volume create my_vol` in docker-compose.yml, declare volumes with property `external: true`. This tells docker compose not to create volumes. If external = false, then docker compose will prefix the volume declared with the directory name. Example: /home   /sam     /docker       /my_app         - docker-compose.yml The volume name will end up being `my_app_my_vol` Example docker-compose.yml: ``` version: "3" volumes:   my_vol:     external: true services:   my_app:     volumes:       - my_vol:/data <-- attach volume to /data inside container ... ... ```